Angularjs 在两条路线之间保存一些搜索信息
我有一条路线Angularjs 在两条路线之间保存一些搜索信息,angularjs,Angularjs,我有一条路线 app.config(function ($routeProvider) { $routeProvider. when("/questions", {controller:"Questions", templateUrl: "questions.html"}). when("/objections", {controller: "Objections", templateUrl: "objections.html"}). when("/objections/
app.config(function ($routeProvider) {
$routeProvider.
when("/questions", {controller:"Questions", templateUrl: "questions.html"}).
when("/objections", {controller: "Objections", templateUrl: "objections.html"}).
when("/objections/:oId", {controller: "Objections", templateUrl: "objections.html"}).
when("/persons", {controller: "Persons", templateUrl: "persons.html"}).
when("/persons/:pId", {controller: "Persons", templateUrl: "persons.html"}).
when("/questions/:qId", {controller: "Questions", templateUrl: "questions.html"}).
otherwise({redirectTo : "/persons"});
})
以及/objections和/objections/:pId的一个模板
<script type="text/ng-template" id="objections.html">
<div class="stroke">
<label>Поиск: <input class="border" type="text" ng-model="search.text"></label>
<ul class="objections-objections left_column">
<li class="border" ng-repeat="objection in objections | filter:search">
<a href="#/objections/{{objection.id}}">
{{objection.text}}
</a>
</li>
</ul>
<div class="right_column">
<p class="header"></p>
<p class="text">
<span>ID возражения: {{objection.id}}</span>
<br>
<textarea class="border" name="" id="" cols="30" rows="10" ng-model="objection.text"></textarea>
</p>
<ul class="questions-objections" ng-show="objection.questions.length">
<span>Список вопросов</span>
<li class="border" ng-repeat="question in objection.questions">
<a href="#/questions/{{question.id}}">{{question.text}}</a>
</li>
</ul>
<p class="footer">
<button ng-click="add()">Добавить</button>
<a href="" ng-click="delete(objection)">Удалить</a>
<a href="" class="save" ng-click="save()">Сохранить</a>
<a href="" class="close" ng-click="cancel()">Закрыть</a>
</p>
</div>
Поиск:
-
同上:{{objective.ID}
Список вопросов
-
所以,当我在搜索字段中输入文本并对列表项进行排序后,我单击其中一个项并查看sleared seearch字段
我应该如何重新编写代码,使search.text指令在此路由之间不会重置
谢谢当视图以角度变化时,有多种方法可以保存对象
- 您可以在$rootScope(可以注入任何控制器)上定义搜索条件,例如$rootScope.searchCriteria={term:null};然后在模板中绑定到此属性。您可以直接使用
ng model=“searchCriteria.term”
- 如果有,可以在ng view的父控制器上定义属性。比如
<div ng-controller="rootController">
<ng-view/>
</div>
appRoot.controller("Questions",
["$scope", "searchCriteria",
function ($scope, searchCriteria ) {