Google给了我错误:“TypeError:无法读取未定义的属性'open'”以响应我的ui-bootstrap模块。我一直在使用其他ui-bootsrap指令。
我没有正确宣布模态依赖吗?
angular.module('ireg').directive('study', function (studyFactory) {
return {
restrict:'E',
scope: {
objectid:'@objectid'
},
templateUrl: '/ireg/components/study/study.html',
link: function (scope, element, attrs, $modal) {
scope.openMilestonesDialog = function () {
var modalInstance = $modal.open({
animation: $scope.animationsEnabled,
templateUrl: '/ireg/components/add-milestones/addMilestonesDialog.html',
controller: '/ireg/components/add-milestones/addMilestonesDialogController.js',
size: lg
});
};
}//end of link
}
});
angular.module('ireg').controller('addMilestonesDialogController', function ($scope, $modalInstance, studyId) {
$scope.ok = function () {
$modalInstance.close();
};
});
答案 0 :(得分:1)
您应该在directive
函数中包含$ modal服务,而不是link
函数:
angular.module('ireg').directive('study', function (studyFactory, $modal) {
return {
restrict:'E',
scope: {
objectid:'@objectid'
},
templateUrl: '/ireg/components/study/study.html',
link: function (scope, element, attrs) {
scope.openMilestonesDialog = function () {
var modalInstance = $modal.open({
animation: $scope.animationsEnabled,
templateUrl: '/ireg/components/add-milestones/addMilestonesDialog.html',
controller: '/ireg/components/add-milestones/addMilestonesDialogController.js',
size: 'lg'
});
};
}//end of link
}
});
是的,Alberto I.N.J.是的,你应该将size
属性设置为字符串。
答案 1 :(得分:1)
您应该将$ model注入指令本身并将lg更改为'lg'
angular.module('ireg').directive('study', function (studyFactory, $modal) {
return {
restrict:'E',
scope: {
objectid:'@objectid'
},
templateUrl: '/ireg/components/study/study.html',
link: function (scope, element, attrs) {
scope.openMilestonesDialog = function () {
var modalInstance = $modal.open({
animation: $scope.animationsEnabled,
templateUrl: '/ireg/components/add-milestones/addMilestonesDialog.html',
controller: '/ireg/components/add-milestones/addMilestonesDialogController.js',
size: 'lg'
});
};
}//end of link
}
});