I have a basic application that retrieves some data through the $ http service, however it does not display data in the template when the template is supported from the template cache. My code is as follows:
angular.module('app', [])
api service:
.factory('api', function($http, $q) {
return {
getCars: function() {
return $http.get('api/cars');
}
};
})
controller using the service:
.controller('carsCtrl', function($scope, api) {
api.getCars().success(function(data) {
$scope.cars = data;
});
})
route setup:
.config(function($routeProvider) {
$routeProvider.when('/cars', {
templateUrl: 'cars.html',
controller: 'carsCtrl'
});
});
and pattern cars.html
<div ng-repeat="car in cars">
{{ car }}
</div>
this works the first time the browser is accessed /cars, however, if I click the "Back" button in the browser to click on the URL a second time without reloading the page, {{car}}it will not be displayed. If cars.htmlplaced in a cache pattern as follows:
angular.module('app').run(function($templateCache) {
$templateCache.put('cars.html', '<div ng-repeat="car in cars">{{ car }}</div>');
});
snapping is {{car}}also not displayed.
, , Angular promises , . - , , ?