2016-08-11 45 views
1

当我将url更改为“/ nameDisplay”时,我似乎无法获取我的'nameDisplay'组件。它不显示任何错误,它只是不插入模板到UI视图。如果我在'状态'中使用模板而不是组件,那么它可以工作,否则它不显示任何内容。使用Angular UI路由器呈现组件

我使用的版本是: 角 - 1.5.8 角UI路由器 - 直接在用户界面路由器配置0.3.1

angular.module('app.nameDisplay', [uiRouter]) 
.component('nameDisplay', { 
    controller: function(){ 
     this.name = "Keir Beckett"; 
     this.age = 24; 
     this.changeInfo = function(){ 
      this.name = "Golash Bista"; 
      this.age = 66; 
     } 
    }, 
    template: "" + 
     "<div>" + 
      "<h2>{{$ctrl.name}}</h2>" + 
      "<h4>{{$ctrl.age}}</h4>" + 
      "<button ng-click='$ctrl.changeInfo()'>Change Info</button>" + 
     "</div>" 
}).config(($stateProvider, $urlRouterProvider) => { 
    $stateProvider.state('nameDisplay', { 
     url: '/nameDisplay', 
     component: 'nameDisplay' 
    }) 
    .state("otherDisplay", { 
     url: '/otherDisplay', 
     template: '<h1>Other Display</h1>' 
    }); 
    $urlRouterProvider.otherwise('/'); 
}) 
.name; 
+1

我从来没有见过'component'作为'state'对象的属性...这是一种新的语法?通常,这是通过使用'template:'''完成的。 – Claies

回答