0
請。幫幫我。我已經正式看過這麼多的教程,我的大腦即將完全崩潰。救救我,stackoverflow,你是我唯一的希望。ng-repeat angularjs es6不起作用
我想用ng-repeat來獲取要顯示的汽車列表。我嘗試了許多不同的方法,無濟於事。
首頁視圖:
<h2>
Welcome to homepage</h2>
<p>{{controller.message}}</p>
<li ng-repeat="car in controller.cars">
{{car.name}}
</li>
</body>
controllers.ts
namespace myapp.Controllers {
export class HomeController {
public message = 'Hello from the home page!';
public movies;
constructor(carService:myapp.Services.CarService) {
this.cars = carService.listCars();
}
}
export class AboutController {
public message = 'Hello from the about page!';
}
}
services.ts
namespace myapp.Services {
export class CarService {
private CarResource;
public listCars() {
return this.CarResource.query();
}
constructor($resource: ng.resource.IResourceService) {
this.CarResource = $resource('/api/cars');
}
}
angular.module('myapp').service('carService', CarService);
export class MyService {
}
angular.module('myapp').service('myService', MyService);
}
所以基本上....我需要讓賽車API給我的信息---它似乎並不是這樣做的。我試圖使用$ http而不是資源。不。我已閱讀並重新閱讀代碼。我需要朝正確的方向輕推。我已經仔細查看了代碼,玩了很多次連接點遊戲,我只是沒有看到這裏丟失的東西。它似乎沒有從API中獲取任何數據(我已經把console.log放在了幾個地方來檢查這個,沒有任何數據),所以有些事情不能將API連接到其餘的我的代碼。我只是不完全確定究竟是什麼。
您的問題的全部內容必須**在您的問題中,而不僅僅是關聯。鏈接腐爛,使問題及其答案在未來的人們中毫無用處,人們不應該離開現場去幫助你。在**問題中放置一個[mcve] **,最好使用Stack Snippets('<>'工具欄按鈕)使其可運行。更多:[*我如何提出一個好問題?*](/ help/how-to-ask) –
您是否看到*「來自主頁的Hello!」*消息?我不太瞭解TypeScript,但是沒有在你的控制器中使用「公共汽車」會影響模板中的屬性可視性? – Phil
是的,我確實看到了。 –