gpt4 book ai didi

AngularJS 和 ui.bootstrap.modal 服务 templateUrl - 我可以使用 Angular 路由吗?

转载 作者:行者123 更新时间:2023-12-03 07:01:12 25 4
gpt4 key购买 nike

我对 Angular 还很陌生,但很喜欢它!我正在尝试创建一个模式对话框来显示部分 View 。 ui.bootstap.modal 有一个选项,它将 URL 带到要显示的部分 View 。我的应用程序模块上配置了一条路由,如下所示:

angular.module('buggy').config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/lists', {
templateUrl: 'views/lists/list.html'
}).
when('/lists/create', {
templateUrl: 'views/lists/create.html'
}).
when('/lists/:listId', {
templateUrl: 'views/lists/partials/view.html'
}). //more stuff

我想显示上述路由中定义为 when(/lists/:listId) 的部分模板。因此,在我的 Controller 中,我尝试打开模式对话框,如下所示:

 $scope.showList = function (list) {
$modal.open({
templateUrl:'lists/' + list._id,
scope:$scope
});
}

模式对话框打开,但内容只是[object]。我需要在服务器端定义路由还是可以使用 Angular 路由返回部分内容?

谢谢!

最佳答案

我对 $routeProvider 的理解是有缺陷的。我责怪多年的 jQuery'n;) 我现在已经可以使用了。我相信 $routeProvider 返回了我的模块配置中定义的 Controller 实例;不是实际的模板。我已经像这样更改了代码:

 $scope.showList = function (list) {
$scope.currentList = list;
$modal.open({
templateUrl: 'views/lists/modals/view.html',
backdrop: false,
scope: $scope,
controller: 'modalCtrl'
});
}

如果这不是一个好的解决方案..请发表评论。关于 Angular,我还有很多东西需要学习。

谢谢!

关于AngularJS 和 ui.bootstrap.modal 服务 templateUrl - 我可以使用 Angular 路由吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20846603/

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