如何在角度应用程序中注入 $stateProvider? [英] How inject $stateProvider in angular application?
问题描述
我尝试使用 angular-ui,并尝试注入 $stateProvider:
html
<头><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular-resource.min.js"></script><script src="http://angular-ui.github.io/ui-router/release/angular-ui-router.min.js"></script><script src="test/appModule.js"></script>头部><身体><div ng-app="appModule"><div ng-controller="appController">{{日期}}
</html>
js (test/appModule.js)
var module = angular.module("appModule", ['ui.router']);module.controller('appController', ['$scope', '$stateProvider',函数($scope,$stateProvider){$scope.date = new Date();}]);
堆栈跟踪
错误:未知提供者:$stateProviderProvider <- $stateProvider在错误(本机)在 https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js:28:236...
如果我删除带有注释的 $stateProvider 和 ui.router 一切都会正常的:
var module = angular.module("appModule"/*, ['ui.router']*/);module.controller('appController', ['$scope'/*, '$stateProvider'*/,函数($scope,$stateProvider){$scope.date = new Date();}]);
那么注入问题$stateProvider有什么解决办法吗?
PS 我已经尝试过 ui 示例 它有效,但我不明白为什么我的没有.
在控制器中使用时必须使用 $state
:
angular.module("appModule", ['ui.router']).controller('appController', ['$scope', '$state', function ($scope, $state) {$scope.date = new Date();}]);
您只能在配置中使用状态提供程序,例如:
angular.module('appModule').config(['$stateProvider', function($stateProvider){/* 与状态提供者一起使用 */})];
I try to use angular-ui, and try to inject $stateProvider:
html
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular-resource.min.js"></script>
<script src="http://angular-ui.github.io/ui-router/release/angular-ui-router.min.js"></script>
<script src="test/appModule.js"></script>
</head>
<body>
<div ng-app="appModule">
<div ng-controller="appController">
{{date}}
</div>
</div>
</body>
</html>
js (test/appModule.js)
var module = angular.module("appModule", ['ui.router']);
module.controller('appController', ['$scope', '$stateProvider',
function ($scope, $stateProvider) {
$scope.date = new Date();
}]);
stack trace
Error: Unknown provider: $stateProviderProvider <- $stateProvider
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js:28:236
...
If I remove $stateProvider and ui.router with comments everything will work:
var module = angular.module("appModule"/*, ['ui.router']*/);
module.controller('appController', ['$scope'/*, '$stateProvider'*/,
function ($scope, $stateProvider) {
$scope.date = new Date();
}]);
So the problem with injection $stateProvider any ideas about resolving?
P.S. I have tried ui sample it works, but I cannot figure out why mine does not.
When using it in a controller you have to use $state
:
angular.module("appModule", ['ui.router']).controller('appController', ['$scope', '$state', function ($scope, $state) {
$scope.date = new Date();
}]);
You can only use the state provider in the config, for example:
angular.module('appModule').config(['$stateProvider', function($stateProvider){
/* do w/e with state provider */
})];
这篇关于如何在角度应用程序中注入 $stateProvider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!