angular.js - 两个direcitve如何获取值
问题描述
两个不同的DIRECTIVE如何取对应scope中的值JS代码
.directive(’save’,function(){ return{restrict:’EAC’,template:’<p id='btnSave'><img src='https://www.haobala.com/wenda/images/savePic.png'></p>’,scope:{ goodsName: ’@goodName’},link:function(scope,element,attrs){ var childElem = element.find(’toggleName’); var childScope = childElem.isolateScope(); element.on(’click’, function() { var jsonData = scope.goodName; alert(jsonData);});} };});
.directive(’toggleName’, function() {return { restrict: ’ECA’, templateUrl: ’views/partials/toggleName.html’, transclute: true, link: function(scope, element, attrs) {scope.toggleName = function() { scope.isSuccessName = !scope.isSuccessName;}; }}; })
HTML代码
<p class='realInputCon fr'><input type='text' maxlength='255' placeholder='请输入' ng-model='goodName'> </p>
save取togglename中的goodName
问题解答
回答1:使用require就搞定了
.directive(’toggleName’, function() {return { restrict: ’ECA’, templateUrl: ’views/partials/toggleName.html’, controller: function($scope) {$scope.goodName = ’togglename’;this.getName = function() { return $scope.goodName;}; }, transclute: true, link: function(scope, element, attrs) {scope.toggleName = function() { scope.isSuccessName = !scope.isSuccessName;}; }}; }).directive(’save’,function(){ return{restrict:’EAC’,template:’<p id='btnSave'><img src='https://www.haobala.com/wenda/images/savePic.png'></p>’,require: ’toggleNmae’,link:function(scope,element,attrs, toggleNameController){ var childElem = element.find(’toggleName’); var childScope = childElem.isolateScope(); element.on(’click’, function() { var jsonData = scope.goodName; alert(jsonData);}); //这里就是toggleName控制器的使用了 toggleNameController.getName();} };});
相关文章:
1. debian - docker依赖的aufs-tools源码哪里可以找到啊?2. dockerfile - [docker build image失败- npm install]3. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?4. docker绑定了nginx端口 外部访问不到5. 如何判断数组写入数据库有重复的值6. boot2docker无法启动7. docker start -a dockername 老是卡住,什么情况?8. macos - mac下docker如何设置代理9. angular.js - angularjs移动端项目需要引入外部的PC网页,iframe宽高设定100%,显示的内容依然是PC那种效果,不是缩放成适配屏10. mac连接阿里云docker集群,已经卡了2天了,求问?