Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使ng模型成为angularjs指令中的可选模型?_Angularjs_Modal Dialog_Angularjs Directive - Fatal编程技术网

如何使ng模型成为angularjs指令中的可选模型?

如何使ng模型成为angularjs指令中的可选模型?,angularjs,modal-dialog,angularjs-directive,Angularjs,Modal Dialog,Angularjs Directive,我有一个指令,我想使ng模型成为可选的 我试过了 return { require: '?ngModel', replace: true, transclude: false, //...... } 我用它就像 链接:函数($scope、$element、$attrs、$ctrl){ var getDialogTemplate=$attrs.cxDlgTemplateUrl; $scope.openDialog=函数(确认操作){ var modalInstan

我有一个指令,我想使ng模型成为可选的

我试过了

return {
    require: '?ngModel',
    replace: true,
    transclude: false,
    //......
}
我用它就像

链接:函数($scope、$element、$attrs、$ctrl){
var getDialogTemplate=$attrs.cxDlgTemplateUrl;
$scope.openDialog=函数(确认操作){
var modalInstance=$modal.open({
背景:“静态”,
templateUrl:getDialogTemplate,
控制器:$attrs.cxController,
决心:{
dialogData:函数(){
返回{
dlgData:$ctrl.$modelValue
};
}
}
});
modalInstance.result.then(函数(){
返回确认();
});
};
}

使用指令时,当我没有为ng模型赋值时,仍然会出现错误。

如果未设置
ngModel
,则
链接
函数的第四个参数将为空。您到底遇到了什么错误?我看到您在对话框Data resolve中调用了
dlgData:$ctrl.$modelValue
。您可能应该将其更改为
dlgData:$ctrl&&$ctrl.$modelValue
I get error'无法读取$ctrl的未定义属性。$modelVlaue@MatthiasI为您的解决方案@JoseM获取相同的错误