我想知道如果我可以把一個stateprovider放在別的地方,而不是我的app.js,因爲它會導致我在其他頁面出現問題。StateProvider在AngularJS的其他地方比app.js
app.js
var app = angular.module('myApp', 'ui.router']);
app.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
// route to show our basic form (/form)
.state('form', {
url: '/form',
templateUrl: 'templates/step_Form/form.html?v=' + new Date().getDay()
})
// url will be nested (/form/profile)
.state('form.upload', {
url: '/upload',
templateUrl: 'templates/step_Form/form-upload.html?v=' + new Date().getDay()
})
// url will be /form/interests
.state('form.content', {
url: '/content',
templateUrl: 'templates/step_Form/form-content.html?v=' + new Date().getDay()
})
$urlRouterProvider.otherwise('/form/upload');
})
我控制器
angular.module('myApp').controller('ImportGeneralCtrl', function ($scope, $stateProvider, $urlRouterProvider) {
//myfunctions
}
我集成一個多步驟的形式在我的HTML,使用狀態提供。 我怎樣才能擺脫從app.js的狀態提供者只適用於我的控制器?
通常,控制器會隨着狀態或狀態映射到具有控制器的組件。 IIRC,你不能在你的控制器中注入'$ stateProvider'和'$ urlRouterProvider',因爲它們是提供者。 –