我在使用带有ui-select2组件的require / ng-require时遇到问题。出于可重用性的原因,我将ui-select2包装在自定义指令中,但无法满足要求。
这是羽毛球:http://plnkr.co/edit/2NaGvDWoEw14BN2few9W?p=preview
在没有指令的情况下尝试并且它正在工作:http://plnkr.co/edit/uE698iFcUNnsYVF2fkOO?p=preview
答案 0 :(得分:2)
问题是angular dosn不支持动态表单元素:
问题#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;
}]);