我想知道我是否可以将状态提供程序放在我的应用程序以外的其他地方.js,因为它会在其他页面中引起一些问题。
应用.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 中集成了一个多步骤表单。如何从应用程序中取出状态提供程序.js仅将其应用于我的控制器?
不能在控制器中使用$stateProvider
或$urlRouterProvider
(提供程序(,因为这些提供程序仅用于配置注入。它可以在所需的任何angular.module('myApp').config()
中使用,但不能在控制器中使用用户提供程序。在控制器中,您只能注入$state
(模块、服务、工厂,例如(:
angular.module('myApp').controller('myController', function ($scope, $state) {}
这个小代码片段向您展示如何创建服务、工厂和提供程序。