mgn*_*gnb 11
我不知道是否有惯用的方法,但如果你使用手动引导程序(即摆脱ng-app),那么重置你可以
示例HTML:
<div id="myid" ng-controller="MyCtrl">
<button ng-click="i = i+1">Add 1</button>
<span>i = {{i}}</span>
<button ng-click="reset()">RESET</button>
</div>
Run Code Online (Sandbox Code Playgroud)
示例controller/JS(也包含jQuery),它将在onload上运行:
var $cleanCopy = $("#myid").clone();
function bootstrap() {
angular.bootstrap(document.getElementById('myid'), ['mymodule']);
}
angular.module('mymodule', []).controller('MyCtrl', function($scope) {
$scope.i = 1;
$scope.reset = function() {
// You need this second clone or angular bootstraps
// into the original clone!
$("#myid").replaceWith($cleanCopy.clone());
bootstrap();
};
});
bootstrap();
Run Code Online (Sandbox Code Playgroud)
这是一个有效的JSFiddle:http://jsfiddle.net/zd377/2/
| 归档时间: |
|
| 查看次数: |
9079 次 |
| 最近记录: |