Javascript 如何传递ng模型对象而不是指令中的值?
我制作了一个输入指令以在多个表单中使用它,所以我需要在提交表单时传递一个ng模型对象,而不是指令中的值 这是密码 HTML:Javascript 如何传递ng模型对象而不是指令中的值?,javascript,angularjs,angularjs-directive,angularjs-ng-model,Javascript,Angularjs,Angularjs Directive,Angularjs Ng Model,我制作了一个输入指令以在多个表单中使用它,所以我需要在提交表单时传递一个ng模型对象,而不是指令中的值 这是密码 HTML: .... .... 指令: angular.module('app'). directive('responsibleSelect', function() { return { restrict: 'E', scope: { model :"=", show : '=', id :
....
....
指令:
angular.module('app').
directive('responsibleSelect', function() {
return {
restrict: 'E',
scope: {
model :"=",
show : '=',
id : '=',
adding : '='
},
controller: 'findCollabOrResCtrl',
template: '<ui-select ng-model="model" reset-search-input="true" tagging="tagTransform" multiple theme="bootstrap">'+
'<ui-select-match placeholder="Escribe los emails de los colaboradores del área" >'+
'{{$item.email}}'+
'</ui-select-match>'+
'<ui-select-choices refresh="refreshCollaborator($select.search,{{ show }},{{ id }},{{ adding }} )"refresh-delay="0" repeat="collaborator.email as collaborator in collaborators">'+
'{{collaborator.email}} '+
'</ui-select-choices>'+
'</ui-select>'
};
});
angular.module('app')。
指令('responsibleSelect',函数(){
返回{
限制:'E',
范围:{
型号:“=”,
显示:“=”,
id:“=”,
添加:'='
},
控制器:“findCollabOrResCtrl”,
模板:“”+
''+
“{{$item.email}”+
''+
''+
“{{collaborator.email}”+
''+
''
};
});
输出html:
<responsible-select model="org.collaborators" show="1" id="1" adding="0" class="ng-isolate-scope">
<div ng-model="model" >...</div>
</responsible-select>
...
我需要这个输出:
<responsible-select model="org.collaborators" show="1" id="1" adding="0" class="ng-isolate-scope">
<div ng-model="org.collaborators" >...</div>
</responsible-select>
...
这可能吗?在指令中使用“要求”
angular.module('app').
directive('responsibleSelect', function() {
return {
restrict: 'E',
require: 'ngModel'
scope: {
model :"=",
show : '=',
id : '=',
adding : '='
},
controller: 'findCollabOrResCtrl',
template: '<ui-select ng-model="model" reset-search-input="true" tagging="tagTransform" multiple theme="bootstrap">'+
'<ui-select-match placeholder="Escribe los emails de los colaboradores del área" >'+
'{{$item.email}}'+
'</ui-select-match>'+
'<ui-select-choices refresh="refreshCollaborator($select.search,{{ show }},{{ id }},{{ adding }} )"refresh-delay="0" repeat="collaborator.email as collaborator in collaborators">'+
'{{collaborator.email}} '+
'</ui-select-choices>'+
'</ui-select>'
};
});
在link函数中,获取值并传递给指令的控制器
如果ngModel的要求是可选的,例如,您可以不使用它-使用“?ngModel”
angular.module('app').
directive('responsibleSelect', function() {
return {
restrict: 'E',
require: 'ngModel'
scope: {
model :"=",
show : '=',
id : '=',
adding : '='
},
controller: 'findCollabOrResCtrl',
template: '<ui-select ng-model="model" reset-search-input="true" tagging="tagTransform" multiple theme="bootstrap">'+
'<ui-select-match placeholder="Escribe los emails de los colaboradores del área" >'+
'{{$item.email}}'+
'</ui-select-match>'+
'<ui-select-choices refresh="refreshCollaborator($select.search,{{ show }},{{ id }},{{ adding }} )"refresh-delay="0" repeat="collaborator.email as collaborator in collaborators">'+
'{{collaborator.email}} '+
'</ui-select-choices>'+
'</ui-select>'
};
});
link: function ($scope, $element, attrs, ngModelCtrl)