1
在角度ui路由器tutorial中,所有状态都在同一个js文件中定义。Angularjs ui路由器状态定义
myApp.config(function($stateProvider) {
// An array of state definitions
var states = [
{ name: 'hello', url: '/hello', component: 'hello' },
{ name: 'about', url: '/about', component: 'about' },
{
name: 'people',
url: '/people',
component: 'people',
resolve: {
people: function(PeopleService) {
return PeopleService.getAllPeople();
}
}
},
{
name: 'people.person',
url: '/{personId}',
component: 'person',
resolve: {
person: function(people, $stateParams) {
return people.find(function(person) {
return person.id === $stateParams.personId;
});
}
}
}
]
// Loop over the state definitions and register them
states.forEach(function(state) {
$stateProvider.state(state);
});
});
但是,当创建一个大的应用程序时,我们可能会有很多状态。通常情况下,一个国家会调用一个调用模板并可能使用服务等的组件。
因此,我使用一个单独的js文件来定义状态,同为我组件,模板,做服务,...
所以我可以有例如:
- 家.stt.js(用于状态)
- home.srv.js(服务)
- home.cpt.js(对于成分)
- home.html的(用于视图)
这是一个很好的做法吗?或者最好是在同一个文件中定义所有状态?
在同一个文件中定义的所有状态都不好 – Akashii
哈哈埃迪,你再次=)我真的很想知道你心中是怎么回事。你的方法是“不同的”:P – lin