[英]Angular UI Router: Cannot log inside of .config
I've been trying to link up components of a simple Angular app but cannot seem to get my initial view state to load. 我一直在尝试链接一个简单的Angular应用程序的组件,但是似乎无法加载我的初始视图状态。 One main issue seems to be that I can't even log inside of my .config setup (despite making sure that everything is syntactically correct). 一个主要问题似乎是我什至无法登录我的.config设置(尽管确保语法上正确无误)。 As far as I can tell (after some testing) all of my files are in the right locations). 据我所知(经过一些测试),我的所有文件都位于正确的位置。
Anybody see any glaring mistakes? 有人看到任何明显的错误吗?
index.html: index.html:
<!DOCTYPE html>
<html>
<head></head>
<title>Thing</title>
<body class="container">
<div class="row">
<div class="span12">
<div class="well" ui-view></div>
</div>
</div>
<!-- dependencies -->
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js"></script>
<script src="//angular-ui.github.io/ui-router/release/angular-ui-router.js"></script>
<!-- css files -->
<!-- application files -->
<script src="js/app.js"></script>
<script src="js/payments.js"></script>
<!-- Google Maps -->
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
</body>
</html>
app.js: app.js:
var paymentApp = angular.module('paymentApp', ['ui.router'])
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/payments')
// Now set up the states
console.log("in config")
$stateProvider
.state('payments', {
url: "/payments",
templateUrl: "view/payments.html"
})
});
payments.html: Payments.html:
<h1>Payments Page</h1>
<div class="buttons">
<button>Click Me!</button>
</div>
<div class="search"></div>
<div class="payments"></div>
Quite a simple mistake to make - you have forgotten to bootstrap your angular app. 很容易犯一个错误-您忘记了引导您的角度应用程序。
You need to add the ng-app directive somewhere and point it to your module. 您需要在某处添加ng-app指令并将其指向您的模块。
Eg 例如
<html ng-app="paymentApp">
https://docs.angularjs.org/api/ng/directive/ngApp https://docs.angularjs.org/api/ng/directive/ngApp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.