更新他们已经停止在这个版本的路由器上工作,并开始使用不同的 API 的版本 3。 As of June 20, 2016 there was no recommended way 将路由器 v3 与 Angular 1 一起使用。我不确定这是否已经改变。下面这个问题和答案与路由器 v2(又名 ComponentRouter)有关。
过时的 API
一些站点表明 Angular 1 中的一个组件(用于新路由器的目的)是一个注册为 [name]Controller 的控制器和一个从 component/[name]/[name].html 中提取的模板。现在已经过时了。
新 API
这个discussion 包含最近的信息,解释了如何获得最新的 Angular 1 新路由器版本。
配置中使用的组件映射到使用组件名称注册的指令。看到这个sample。
angular.module('app.home', [])
.directive('home', function() {
return {
template: 'Hello {{ home.text }}',
controller: function HomeController() {
this.text = 'World';
},
controllerAs: 'home'
}
});
Angular 1.5 有一种新的注册组件语法,请参阅here。我用这种语法使用它:
angular.module('app.home', [])
.component('home', {
restrict: "EA",
template: 'Hello {{ home.text }}',
controller: function HomeController() {
this.text = 'World';
}
// to configure a child route
//,$routeConfig: [
// { aux: "/son", component: "son", as: "Left" },
// { aux: "/daughter", component: "daughter", as: "Left" }]
});