[英]AngularJS route with routeprovider not working
I have this index.html page: 我有这个index.html页面:
<html>
<head ng-app="myApp">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test App/title>
<link rel="stylesheet" href="app.css">
</head>
<body ng-controller="mainController">
<a href="#/index2">index2</a>
<div ng-view></div>
<script src="vendor/angular/angular.js"></script>
<script src="vendor/angular-route/angular-route.js"></script>
<script src="app.js"></script>
</body>
</html>
And this is my app.js script: 这是我的app.js脚本:
'use strict';
var myApp = angular.module('myApp', ['ngRoute'])
.config(function ($routeProvider) {
$routeProvider
.when('/index2', {
templateUrl: 'views/index2.html'
})
.otherwise({redirectTo: '/views/index2.html'});
});
myApp.controller('mainController', function ($scope) {
});
And my views/index2.html is contains only single 123 element. 而且我的views / index2.html仅包含单个123元素。 When I'm clicking link on my index.html, nothing happens, no routing.
当我单击index.html上的链接时,什么也没有发生,也没有路由。 What I'm doung wrong?
我错了吗?
upd: I run it from IntelliJ IDEA so it's nothing about webserver is missing ,I think. upd:我想是从IntelliJ IDEA运行它的,所以网络服务器完全没有丢失。
You have ng-app
directive applied to your head
tag: 您已将
ng-app
指令应用于您的head
标签:
<head ng-app="myApp">
This means that ng-app
will apply to head
tag only. 这意味着
ng-app
仅适用于head
标签。 Instead you need to move it to your html
tag: 相反,您需要将其移至
html
标记:
<html ng-app="myApp">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.