角 - 不同的路线,相同的模板/控制器,不同的加载方法 [英] Angular - different route, same template/controller,different loading method
问题描述
我想使用的路线,但我总是想用相同的模板和放大器;控制器。我有这样的路线:
I want to use routes, but I always want to use same template & controller. I have routes like this:
**a/:albumid**
和
**i/:imageid**
在第一种情况下我要加载图像阵列,并将它们添加到列表中。在第二种情况下,我想加载单个图像,并将其添加到列表中。
In the first case I want to load an array of images and add them to a list. In the second case I want to load a single image and add it to a list.
因此,差别只在数据加载。什么是做到这一点的最有效方法是什么?
So the difference is only in data loading. What is the most efficient way to do this?
也有可能进行动画NG-说明了什么?像jQuery的了slideDown?
Also is it possible to animate ng-show? Something like jQuery's slideDown?
推荐答案
看看这篇文章,它描述了一个方式做你想要什么:
Check out this article, it describes a way to do exactly what you want:
<一个href=\"http://www.bennadel.com/blog/2420-Mapping-AngularJS-Routes-Onto-URL-Parameters-And-Client-Side-Events.htm\">http://www.bennadel.com/blog/2420-Mapping-AngularJS-Routes-Onto-URL-Parameters-And-Client-Side-Events.htm
我使用的技术,效果很好。
I've used the technique, it works well.
在简单地说,像这样的路由:
In a nutshell, something like this for routing:
$routeProvider
.when("/a/:album_id", {
action: "album.list"
}).when("/i/:imgid", {
action: "images.load"
})
然后在您的控制器,您可以访问 $ route.current.action
并做相应的事情。关键是要建立在你的一个功能,它所有的工作(本文称之为渲染()
),然后调用该函数时$ routeChangeSuccess火灾:
Then in your controller you can access $route.current.action
and do the appropriate thing. The trick is to create a function in you controller that does all the work (the article calls it render()
) and then call that function when $routeChangeSuccess fires:
$scope.$on(
"$routeChangeSuccess",
function( $currentRoute, $previousRoute ){
// Update the rendering.
render();
}
);
这篇关于角 - 不同的路线,相同的模板/控制器,不同的加载方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!