从出擦页面停止角JS NG-视图 [英] Stop Angular JS ng-view from wiping the page out
问题描述
好吧,我需要能够停止 NG-视图
从擦内容了,我需要有NG-认为有,因为它是不言而喻的唯一的地方它不会(也不能)核弹整个应用程序。
Okay, I need to be able to stop ng-view
from wiping the content away, I need to have the ng-view there since it's the only place it goes where it doesn't (and can't) nuke the whole application.
我有一个滚动的它,但里面的内容变化,当一个人做了搜索(应用程序的整点是搜索),但只是在页面加载了角清空NG-视图。
I have a scroller inside of it but the contents change when a person does a search (the whole point of the app is to search) but just loading the page up Angular empties the ng-view.
任何方式阻止这种默认行为?
Any way to stop that default behaviour?
推荐答案
一个不同的(也许是更好的*)的方法是使用一个指令采取的内容NG-视图
,并将其存储为模板之前,它的编译(并清除)。
A different (and perhaps nicer*) approach is to use a directive to take the content of the ng-view
and store it as a template before it's compiled (and cleared).
angular.module('myApp', ['ngRoute'])
.directive('foo', ['$templateCache', function($templateCache)
{
return {
restrict: 'A',
compile: function (element)
{
$templateCache.put('bar.html', element.html());
}
};
}])
.config(function($routeProvider, $locationProvider)
{
$routeProvider.when('/', { templateUrl: 'bar.html' });
});
这样,你不需要包装在脚本标记的 NG-视图
的内容。
<div ng-app="myApp">
<div foo ng-view>
<ul>
<li> test1 </li>
<li> test2 </li>
<li> test3 </li>
<li> test4 </li>
</ul>
</div>
</div>
*)我在我自己的角度相当新的,所以我没有足够深的角心态知道它完全是适当的做这些事情。
*) I'm fairly new at angular myself, so I'm not deep enough in the angular mindset to know if it entirely "proper" to do these things.
这篇关于从出擦页面停止角JS NG-视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!