【发布时间】:2014-12-08 04:40:11
【问题描述】:
我有一个由部分视图组成的单页应用程序。我想在不重新加载页面的情况下刷新点击元素的部分视图。最好的方法是什么?
【问题讨论】:
-
你能给我们一个代码示例吗?
我有一个由部分视图组成的单页应用程序。我想在不重新加载页面的情况下刷新点击元素的部分视图。最好的方法是什么?
【问题讨论】:
我认为 Aliz 在您的答案下方的评论将是每个人都在问的问题,但我会尝试回答您的问题,假设下面的示例代码类似于您要存档的内容。
<section controller='ctrl'>
<span>{{ text }}</span>
<button ng-click="update()">update text</button
</section>
angular.module('myApp')
.controller('ctrl', ['$scope', '$timeout', function($scope, $timeout){
// the data inside $scope.text can be dynamically populated from an AJAX call result. (doesn't matter where its from)
$scope.text = 'hello world!';
$scope.update = function() {
// sometimes this doesn't work and you need to call $scope.$apply below to forcefully update the view.
$scope.text = 'new text';
$timeout(function(){
$scope.$apply();
}, 0);
}
}];
如果这不是您要归档的内容,请发布您的代码以获得进一步的帮助。
【讨论】: