SOS! I am drowning in tutorials and my brain is on the verge of exploding. StackOverflow, please save me from this coding nightmare!
I am struggling to use ng-repeat to display a list of cars. No matter how many times I attempt it, I can't seem to get it right.
Homepage view:
<h2>
Welcome to our 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 = 'Greetings from the home page!';
public movies;
constructor(carService:myapp.Services.CarService) {
this.cars = carService.listCars();
}
}
export class AboutController {
public message = 'Greetings 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);
}
In essence... I am unable to retrieve information from the car API as expected. I've tried using $http instead of resource, but it didn't work. Despite reviewing the code multiple times, I can't figure out why the API data isn't being fetched. There seems to be a disconnect between the API and my code, but I'm unable to pinpoint the exact issue.