我想按照这个教程:
https://angular.github.io/router/getting-started
为什么AppController的。$ routeConfig未定义?
angular.module('应用',['ngNewRouter','app.home']) .controller('AppController的',['$路由器,AppController的]);AppController的。$ routeConfig([ {路径:'/',分量:'家'}]);功能的AppController($路由器){}
我的html:
<!DOCTYPE HTML>< HTML LANG =ENGT&;< HEAD> <间的charset =UTF-8> <基本href =/> <标题>我的应用程序< /标题>< /头><机身NG-应用=对myAppNG控制器=AppController的为应用程序>< DIV NG-视>< / DIV>&所述; SCRIPT SRC =node_modules /角度/ angular.js>&下; /脚本><脚本SRC =node_modules /角新的路由器/距离/ router.es5.js>< / SCRIPT><脚本SRC =./组件的/ home / home.js>< / SCRIPT>&所述; SCRIPT SRC =app.js>&下; /脚本>< /身体GT;< / HTML>
解决方案
我发现这个手册我的角1.5,但笔者上班使用1.3角 http://www.sitepoint.com/introduction-futuristic-new-router- angularjs /
这里是code应该为你工作:
angular.module('应用',['ngNewRouter','app.home']) .controller('AppController的',['$路由器,功能($路由器){ $ router.config([ {路径:'/',redirectTo:'/家}, {路径:'/家',组成:家}, {路径:'/例如',分量:例如'} ]); this.name ='游客';}]);
和HTML中的这两行更改为:
<机身NG控制器=AppController的>< DIV NG-视>< / DIV>
I'm trying to follow this tutorial:
https://angular.github.io/router/getting-started
Why is AppController.$routeConfig undefined?
angular.module('app', ['ngNewRouter', 'app.home'])
.controller('AppController', ['$router', AppController]);
AppController.$routeConfig([
{path: '/', component: 'home' }
]);
function AppController ($router) {}
my html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<base href="/">
<title>My app</title>
</head>
<body ng-app="myApp" ng-controller="AppController as app">
<div ng-viewport></div>
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-new-router/dist/router.es5.js"></script>
<script src="./components/home/home.js"></script>
<script src="app.js"></script>
</body>
</html>
解决方案
I found this manual to work for me with angular 1.5 but author uses angular 1.3 http://www.sitepoint.com/introduction-futuristic-new-router-angularjs/
here is the code that should work for you:
angular.module('app', ['ngNewRouter', 'app.home'])
.controller('AppController', ['$router', function($router){
$router.config([
{ path:'/', redirectTo:'/home' },
{ path:'/home', component:'home' },
{ path:'/example', component:'example' }
]);
this.name='visitor';
}]);
and in html change these two lines to:
<body ng-controller="AppController">
<div ng-viewport></div>