我在ui-select2组件中使用require/ng-require有问题。出于可重用性的原因,我将ui-select2封装在自定义指令中,但无法获得所需的工作
这是活塞:http://plnkr.co/edit/2NaGvDWoEw14BN2few9W?p=preview
尝试没有指令,它的工作:http://plnkr.co/edit/uE698iFcUNnsYVF2fkOO?p=preview
问题是angular不支持动态表单元素:
第1404期https://github.com/angular/angular.js/issues/1404
解决方法(直到1.3版本出来):
app.config(['$provide', function($provide) {
$provide.decorator('ngModelDirective', ['$delegate', function($delegate) {
var ngModel = $delegate[0], controller = ngModel.controller;
ngModel.controller = ['$scope', '$element', '$attrs', '$injector', function(scope, element, attrs, $injector) {
var $interpolate = $injector.get('$interpolate');
attrs.$set('name', $interpolate(attrs.name || '')(scope));
$injector.invoke(controller, this, {
'$scope': scope,
'$element': element,
'$attrs': attrs
});
}];
return $delegate;
}]);
$provide.decorator('formDirective', ['$delegate', function($delegate) {
var form = $delegate[0], controller = form.controller;
form.controller = ['$scope', '$element', '$attrs', '$injector', function(scope, element, attrs, $injector) {
var $interpolate = $injector.get('$interpolate');
attrs.$set('name', $interpolate(attrs.name || attrs.ngForm || '')(scope));
$injector.invoke(controller, this, {
'$scope': scope,
'$element': element,
'$attrs': attrs
});
}];
return $delegate;
}]);
来源:http://jsfiddle.net/Thinkscape/23RPt/