gpt4 book ai didi

javascript - 模态在指令中返回未定义

转载 作者:行者123 更新时间:2023-12-02 15:59:34 25 4
gpt4 key购买 nike

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();
};


});

最佳答案

您应该在 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 属性设置为字符串。

关于javascript - 模态在指令中返回未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31319822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com