【发布时间】:2015-05-26 07:31:19
【问题描述】:
我正在开发一个具有 2 个视图的单页应用程序:主页和仪表板。
“家”状态有一个搜索表单。提交表单时,使用$window.location.assign('/#/dashboard'); 加载仪表板视图。
当从搜索加载仪表板视图时,我需要自动将选择框值设置为 0。我有执行此操作的代码,但由于某种原因,它在页面加载时没有执行...我我认为这与 Angular 在加载时向页面添加新的 'select' DOM 元素有关。
仪表板视图
<div ng-controller="MainCtrl">
<!-- list all lists -->
<select id="list-select" class="list-select" ng-model="list" ng-options="list as list.title for list in lists">
<option value="">Select List</option>
<!-- when the page loads from search, this will be added...
<option value="0">search</option>
-->
</select>
<!-- end list -->
<hr class="dash">
<!-- words in selected list -->
<ol ng-model="list.words">
<li ng-repeat="word in list.words" id="word-{{word.id}}">
<p>{{ word.title }}</p>
</li>
</ol>
<!-- end words -->
</div>
main.js
$("#list-select").val("0");
请帮忙!
【问题讨论】:
-
您应该考虑只使用
$location服务。 -
我尝试了 $location.path 服务,但它不起作用,所以我只使用了 $window.assign,这与问题/解决方案有关吗?
-
有趣的是,我可能跳了枪脱口而出:]。它可能与解决方案无关,只是一种风格观察。你可以无视。
标签: javascript angularjs