如何注入$ stateProvider在角应用程序?

编程入门 行业动态 更新时间:2024-10-18 22:29:28
本文介绍了如何注入$ stateProvider在角应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试使用角UI 和尝试注入$ stateProvider:

I try to use angular-ui, and try to inject $stateProvider:

HTML

<!DOCTYPE html> <html> <head> <script src="ajax.googleapis/ajax/libs/angularjs/1.0.4/angular.min.js"></script> <script src="ajax.googleapis/ajax/libs/angularjs/1.0.4/angular-resource.min.js"></script> <script src="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 ajax.googleapis/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在角应用程序?

本文发布于:2023-11-07 23:04:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567686.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   stateProvider

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!