-1
道歉提前,我只是在學習AngularJS。雖然我能得到這個實際工作,我想知道有什麼更好的辦法是使用AJAX操作來填充在頁面加載我的看法:更新AngularJS查看使用模型更新AJAX
module.run(['$rootScope', '$location', '$routeParams', '$http', function($rootScope, $location, $routeParams, $http) {
$rootScope.$on('$routeChangeSuccess', function(e, current, pre) {
console.log('Current route name: ' + $location.path());
// Get all URL parameter
console.log($routeParams);
$rootScope.currentEditObject = { name: '' };
if ($routeParams.id) {
if ($location.path().startsWith('/object')) {
$rootScope.type = 'object';
$.ajax({
type: 'GET',
url: 'https://localhost/getObject',
data: {
objectId: $routeParams.id
}
}).success(function(data, status) {
$rootScope.$apply(function() { $rootScope.currentEditObject = data.response.object; });
});
}
}
});
}]);
我開始對$apply
念起來它如何影響摘要,但我懷疑有比這更好的做法。從AJAX請求加載模型的「角度方式」是什麼?
擺脫jQuery的Ajax調用和使用'$ http' - - 這將啓動一個摘要循環,然後將返回的數據應用到'$ scope'元素中,該元素將在視圖中拾取 – tymeJV