刚开始使用angular假如编写的directive同时需要require多个model怎么办?
给你一段刚好在用的代码参考下:
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) { } }; });
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)"/>
<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)"/>
楼上理解错了题主的意思,他的意思是一个指令要require多个指令,其实很简单,只要把require的指令放进数组中就行了,代码如下:
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]; //这样就可以访问依赖指令的控制器了 } }; });
给你一段刚好在用的代码参考下:
directive:
html
楼上理解错了题主的意思,他的意思是一个指令要require多个指令,其实很简单,只要把require的指令放进数组中就行了,代码如下: