0
我有一個包含ng-view的頁面。這個嵌入式模板是一個表格,當單擊一行時切換到該行的詳細模板。我一直無法讓控制器收集「細節」數據併成功顯示它。Angular:無法加載數據併成功更改視圖
通過下面的代碼,通過$ http.get收集數據,並顯示'detail'視圖,但數據未綁定到'detail'視圖。
有人可以請解釋我哪裏錯了嗎?
Controller.js
(function(){
var appName = 'theApp'
var app = angular.module('theApp', ['ngRoute'])
.config(function appConfig($locationProvider, $routeProvider){
$routeProvider
//route that is called when "Show Location" is called below.
.when('/' + appName + '/location/:id', {
controller: 'Controller',
templateUrl: function(params){ return appName + '/location/detail/'+params.id; }
})
.when('/' + appName + '/location',{
controller: 'Controller',
templateUrl: function(params){return appName + '/location/list'}
})
$locationProvider.html5Mode(true);
});
app.controller('Controller', function($scope, $location, $window, $http){
$http.get('/Service/data/location/list').success(function(locationData) {
$scope.locationList = locationList;
$scope.locationDetail = locationDetail;
});
$scope.showLocation = function(id){
$http.get('/Service/data/locations/detail/'+id)
.success(function(locationDetail){
//data exists here
$scope.locationDetail = locationDetail;
//data successfully updated to $scope at this point.
$location.url($location.path() + '/' + id);
//templateUrl successfully shown, but without data.
});
};
})
})();
感謝您的解釋。 – KickinMhl