**这个ui路由器的js文件是否正确。显示的错误是 “错误:未知提供者:来自routerApp的$ stateProvider”
此js文件已加载到Html文件中。
**
var routerApp = angular.module('routerApp', ['ui.router']);
routerApp.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/template1');
$stateProvider
// HOME STATES AND NESTED VIEWS ========================================
.state('template1', {
url: '/temp1',
templateUrl: 'templates/template1.html'
})
// ABOUT PAGE AND MULTIPLE NAMED VIEWS =================================
.state('template2', {
// we'll get to this in a bit
});
});
<!-- MAIN CONTENT -->
<div class="container">
<!-- THIS IS WHERE WE WILL INJECT OUR CONTENT ============================== -->
<div ui-view></div>
</div>
</body>
</html>
请帮助。谢谢提前
答案 0 :(得分:2)
请参见此处:http://plnkr.co/edit/FYxpaHpKgvpEu6f1TZ7l?p=preview
var routerApp = angular.module("routerApp", ["ui.router"]);
routerApp.config(
["$stateProvider", "$urlRouterProvider",
function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/template1");
$stateProvider
.state("template1", {
url: "/template1",
templateUrl: "template1.html",
controller: "tmp1Controller"
})
.state("template2", {
url: "/template2",
templateUrl: "template2.html",
controller: "tmp2Controller"
})
;
}
]);
routerApp.controller("mainCtrl", ["$scope",
function($scope) {
}
]);
routerApp.controller("tmp1Controller", ["$scope",
function($scope) {
}
]);
routerApp.controller("tmp2Controller", ["$scope",
function($scope) {
}
]);
答案 1 :(得分:1)
我有同样的问题,解决了替换
<div ui-view></div>
通过
<ui-view>
<i>Loading ....</i>
</ui-view>