国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

angular.js - 兩個direcitve如何獲取值

瀏覽:218日期:2024-10-11 08:11:06

問題描述

angular.js - 兩個direcitve如何獲取值兩個不同的DIRECTIVE如何取對應scope中的值JS代碼

.directive(’save’,function(){ return{restrict:’EAC’,template:’<p id='btnSave'><img src='http://www.intensediesel.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='http://www.intensediesel.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();} };});

相關文章:
主站蜘蛛池模板: 彰武县| 聂荣县| 高阳县| 从江县| 双柏县| 黎平县| 灵宝市| 搜索| 通江县| 桂东县| 桃园市| 龙里县| 金阳县| 德保县| 信阳市| 利辛县| 光山县| 慈溪市| 青岛市| 周宁县| 淮安市| 区。| 沙洋县| 海林市| 白朗县| 临朐县| 淮安市| 杨浦区| 玉山县| 岑溪市| 十堰市| 临猗县| 农安县| 清河县| 张家口市| 中西区| 库车县| 隆昌县| 大港区| 蒙阴县| 吐鲁番市|