I recently tried creating an AngularJS 1.5 component using TypeScript, but unfortunately, it's not functioning as expected. The data binding seems to be completely broken. Although I can see the data in my console when the $onInit function fires, none of that data is displayed on the screen. This is my first attempt at TypeScript and I would greatly appreciate any guidance or help to point me in the right direction?
Below is the code for my component:
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((response: any) => {
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());
And here is my HTML code:
<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>