angular.js - angular directive中需要依赖多个model怎么办?
仅有的幸福
仅有的幸福 2017-05-15 16:52:45
0
2
564

刚开始使用angular假如编写的directive同时需要require多个model怎么办?

仅有的幸福
仅有的幸福

reply all(2)
为情所困

Let me give you a piece of code that I just used for reference:

directive:

javascriptangular.module('imageupload', []).directive('myCustomer', function() {
  return {
    restrict: 'A',
    scope: {
        image: '=',
        resizeMaxHeight: '@?',
        resizeMaxWidth: '@?',
        resizeQuality: '@?',
        resizeType: '@?',
        selectedfile: '&onFileSelected'
    },
    link: function postLink(scope, element, attrs, ctrl) {
    }
  };
});

html

html<input type="file"
       name="file"
       class="upload"
       id="inputImage2"
       accept="image/*"
       image="image2"
       resize-max-height="300"
       resize-max-width="250"
       resize-quality="0.5" on-file-selected="transferedImage(imageResult)"/>
过去多啦不再A梦

The person upstairs misunderstood the meaning of the question. He meant that one instruction requires multiple instructions. In fact, it is very simple. Just put the require instruction into an array. The code is as follows:

app.directive('directveA',function(){})
    .directive('directiveB',function(){})
    .directive('directiveC',function(){
        return {
            require:['directiveA','directiveB']
            link:function(scope,element,attrs,ctrls){
                var aCtrl=ctrls[0];
                var bCtrl=ctrls[1];
                //这样就可以访问依赖指令的控制器了
            }
        };
    });
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!