1
Мой контроллер/служба извлекает данные из URL-адреса и возвращается без ошибок. Однако повтор для <tbody> не отображает данные. Инспектор не показывает ошибок, и скрипач показывает, что URL-адрес вызван для остальных апи.
Модель
export interface IAuthor {
AuthorId: number;
FirstName: string;
LastName: string;
GoogleAuthorId: string;
CreatedByEmployeeId: any;
CreatedOn: Date;
ModifiedByEmployeeId: any;
ModifiedOn: Date;
PhotoURI: string;
}
Сервис
export class AuthorService implements IAuthorService {
private url: string;
static $inject = ["$http"];
constructor(private $http: ng.IHttpService) {
this.url = "/odata/Author";
}
getAuthors(): ng.IPromise<IAuthor[]> {
return this.$http
.get(this.url)
.then((response: ng.IHttpPromiseCallbackArg<IAuthor[]>): IAuthor[] => {
return response.data;
});
}
}
Контроллер
export class AuthorController implements IAuthorController {
authorItems: IAuthor[];
static $inject: string[] = ["AuthorService"];
constructor(private authorService: Services.IAuthorService) {
var results = this.getAuthors();
}
getAuthors(): IAuthor[] {
this.authorItems = [];
var results = this.authorService.getAuthors()
.then((authorItemsLocal: IAuthor[]): void => {
this.authorItems = authorItemsLocal;
});
return this.authorItems;
}
}
Html
<div class="container" ng-controller="AuthorController as vm">
<h2>Authors</h2>
<div>
<table class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Author ID</th>
</tr>
</thead>
<tbody ng-repeat="c in vm.authorItems">
<tr>
<td>{{ c.FirstName }}</td>
<td>{{ c.LastName }}</td>
<td>{{ c.AuthorId }}</td>
</tr>
</tbody>
</table>
</div>
</div>
Как шаг отладки, появляется ли что-нибудь, если вы поместите некоторые элементы-заполнители в свойство 'authorItems' в конструкторе класса? –
Я инициализировал его с помощью элементов, и он все еще вытирает элементы, и после него появляются две пустые строки. –
Ничто не кажется неправильным, можете ли вы показать нам, как вы регистрируете свой контроллер? Вы можете войти в консоль в результате вызова 'this.authorService.getAuthors()' и показать результат. –