如何注入$ stateProvider在角应用程序? [英] How inject $stateProvider in angular application?
本文介绍了如何注入$ stateProvider在角应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用角UI 和尝试注入$ 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(测试/ appModule.js)
var module = angular.module("appModule", ['ui.router']);
module.controller('appController', ['$scope', '$stateProvider',
function ($scope, $stateProvider) {
$scope.date = new Date();
}]);
堆栈跟踪
Error: Unknown provider: $stateProviderProvider <- $stateProvider
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js:28:236
...
如果我删除的 $ stateProvider 的和的 ui.router 的意见与一切将工作:
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();
}]);
因此,与注射问题的 $ stateProvider 的有关解决任何想法?
PS 我曾尝试 UI样品它的工作原理,但我不明白,为什么我的没有。
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屋!
查看全文