What should I do if I write a directive that requires multiple models at the same time when I first start using Angular?
为情所困2017-05-15 16:54:45
Let me give you a piece of code that I just used for reference:
directive:
javascript
angular.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梦2017-05-15 16:54:45
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];
//这样就可以访问依赖指令的控制器了
}
};
});