gpt4 book ai didi

javascript - AngularJS:将创建/编辑页面与管理页面分开

转载 作者:行者123 更新时间:2023-11-29 15:37:43 24 4
gpt4 key购买 nike

我有单页应用程序和三个页面:ManageList、CreateList、EditList我为它使用一个 Controller 和两个 View (manageView 和 CreateEditView)

when('/manageList', {
templateUrl: settings.baseurl + '/app/modules/sample/list-partial.html',
controller: 'listController',
resolve: {
listName: '$route',


function ($route) {
return {
editList: false,
manageList: true;

}
}]
}
}).
when('/createManageList', {
templateUrl: settings.baseurl + '/app/modules/sample/createEdit-partial.html',
controller: 'listController'
},
resolve: {
listName: '$route',


function ($route) {
return {
editList: false,
manageList: false;

}
}]
}
}).
when('/editList/listName/:listName', {
templateUrl: settings.baseurl + '/app/modules/sample/createEdit-partial.html',
controller: 'listController',
resolve: {
listName: '$route',


function ($route) {
return {
editList: $route.current.params.listName,
manageList: false;

}
}]
}
}).

在 listController 中,我管理由 listName 和 manageList 参数执行的代码

if (listName.editList) {
//code for editing goes here
} else if (listName.manageList) {
//code for managing goes here

} else {
// code for creating goes here
}

问题:是否有更好的方法来分离创建页面的逻辑。否则我真的不喜欢这种邪恶。

最佳答案

您应该创建 3 个 Controller (每个 View 一个)。如果您有一些共同的行为,您可以创建服务或工厂,在功能内部声明并将其注入(inject)所有需要的 Controller 。

Controller 必须很小,您不应该在其中声明所有代码逻辑。

关于javascript - AngularJS:将创建/编辑页面与管理页面分开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25502011/

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