2016-11-29 78 views
0

我創建angularjs使用打字稿1.5組件,但它不工作,當我說這是不工作它的約束力不工作。當它觸發$ onInit函數時,我可以在控制檯中看到數據,但它從不將任何數據放在屏幕上。這是我在打字稿上的第一槍,並且真的會確定是否有人可以將我指向正確的方向?Angularjs 1.5組件與打字稿不工作

我的組件代碼如下

class Users implements ng.IComponentOptions { 
    public bindings: any; 
    public controller: any; 
    public template: string; 
    public templateUrl: string; 
    public transclude: boolean; 
    public controllerAs: string; 

    constructor() { 
     this.controller = UsersController; 
     this.templateUrl = "Template/Index?feature=users&template=users"; 
     this.transclude = false; 
     this.controllerAs = "vm"; 
    } 
} 


class UsersController { 
    public name: string; 
    public test: string; 
    public Users: any[]; 

    static $inject: string[] = ["$http", "repository.user"]; 

    constructor(private $http: any, private RepositoryUser: any) { 
    } 

    public $onInit(): void { 
     this.RepositoryUser.getUsers().then(function (response) { 
      this.Users = response.data; 
      console.dir(this.Users); 
     }); 
    } 

    public setUser(id: number, value: any): void { 
     this.Users[this.Users.indexOf(value)] = value; 

    } 
} 

angular.module("app.users").component("users", new Users()); 

和我的HTML是

<div class="row"> 
    <div class="col-sm-12"> 
     <ng-form> 
      <h2>Users</h2> 

      <div ng-repeat="model in vm.Users track by $index" class="row top10"> 
       <div class="col-sm-8"> 
        <a ui-sref="user-details({ id: model.id })"><strong ng-bind="model.name"></strong></a> 
       </div> 
       <div class="col-sm-4"> 
        <button class="btn btn-default" type="button" ng-click="vm.selectedId=model.id">Select</button> 
       </div> 
      </div> 

     </ng-form> 
    </div> 
</div> 

回答