我正在学习AngularJS.假设我有/ view1使用My1Ctrl,/ view2使用My2Ctrl ; 可以导航到使用制表符,其中每个视图都有自己的简单但不同的形式.
当用户离开然后返回到view1时,如何确保以view1的形式输入的值不会重置?
我的意思是,对于view1的第二次访问如何保持与我离开时模型完全相同的状态?
是否有可能将两个视图绑定到一个控制器,以便无论数据在何处更改(view1,view2或在模型中),两个视图都会更新?它应该像这个例子一样工作(删除杂乱).
<script>
angular.module('foobar', []).controller('ContentCtrl', ['$scope', function($scope) {
$scope.content = {'title': 'Foo', 'subtitle': 'Bar', 'text': 'desc'};
}]);
</script>
<form action="#" ng-controller="ContentCtrl">
<input type="text" ng-model="content.title">
<input type="text" ng-model="content.subtitle">
<textarea ng-model="content.text"></textarea>
</form>
<div ng-controller="ContentCtrl">
<input type="text" ng-model="content.title">
<input type="text" ng-model="content.subtitle">
<textarea ng-model="content.text"></textarea>
</div>
Run Code Online (Sandbox Code Playgroud)
这是一个Plunker:http://plnkr.co/edit/UDs10RhG7mJR8813epwO?p =preview