I am eagerly trying to create a dyanmic $StateProvider:
Standard static $StateProvider:
$stateProvider
.state(\'main\
I think you're calling $stateProvider.state(...)
incorrectly, it takes a state ID and then the configuration object.
Assuming your name
properties are valid and unique you should just be able to do this (or adjust it as needed):
angular.forEach(states, function(state) {
$stateProvider.state(state.name, state);
});
Solution:
var states = [
{ name: 'main', url: '/', templateUrl: '/views/main.html', controller: 'MainCtrl' },
{ name: 'login', url: '', templateUrl: '/views/login-form.html', controller: 'LoginCtrl' },
{ name: 'logout', url: '', templateUrl: '', controller: 'LogoutCtrl' },
{
name: 'sales',
url: '',
templateUrl: '/views/sales-data.html',
controller: 'SalesDataCtrl',
resolve: {
user: 'User',
authenticationRequired:
['user', function(user) { user.isAuthenticated(); }] // <-------------------------
}
}
];
angular.forEach(states, function (state) {
$stateProvider.state(state.name, state);
});