Templates from the cache template are not attached to bindings when returning data from $ http to 1.2+

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 , . - , , ?

+3
1

, (, , SO not sure). . , , :

Plnkr

0

All Articles