我使用typescript创建了angularjs 1.5组件,但是它不起作用,当我说它不起作用时它的绑定根本不起作用。当我触发$ onInit函数时,我可以在控制台中看到数据,但它从不在屏幕上放置任何数据。这是我对打字稿的第一次拍摄,如果有人能指出我正确的方向,那真的会让人感到高兴吗?
我的组件代码在
之下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>
答案 0 :(得分:0)
尝试使用以下语法:https://blogs.infinitesquare.com/posts/web/creer-un-component-angularjs-en-typescript 帖子是法语的,但你可以阅读示例代码。
如果您有更多问题,请与我们联系。