찾다

 >  Q&A  >  본문

angular.js - 两个direcitve如何获取值


两个不同的DIRECTIVE如何取对应scope中的值
JS代码

.directive('save',function(){
    return{
        restrict:'EAC',
        template:'<p class="saveBtn bottomBtn fl" id="btnSave"><img src="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="请输入" class="realCodeField realFieldCommon" ng-model="goodName">
    </p>

save取togglename中的goodName

曾经蜡笔没有小新曾经蜡笔没有小新2744일 전575

모든 응답(1)나는 대답할 것이다

  • 某草草

    某草草2017-05-15 16:56:59

    require를 사용하세요

    으아악

    회신하다
    0
  • 취소회신하다