打破HTML成AngularJS管理模板 [英] Breaking HTML into management templates for AngularJS

查看:100
本文介绍了打破HTML成AngularJS管理模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想,因为我认为这是有趣但它是我一直使用的是什么这是BackboneJS完全不同的评价AngularJS。作为本次评测的部分我想利用我现有的骨干应用的几个页面,并尝试将它们移植到AngularJS。所以,我有以下的HTML布局:

So I am trying to evaluate AngularJS as I think it is interesting however it is quite different from what I have been using which is BackboneJS. As part of this evaluation I want to take a few page of my existing Backbone application and try to port them over to AngularJS. So I have the following html layout:

<html>
    <head>
    </head>
    <body>
        <div class="page-wrapper">
            <div class="header-wrap">
                <ul>
                    <li><a href="#">Ryan Zec</a></li>
                    <li><a href="#">Admin</a></li>
                    <li><a href="#">Logout</a></li>
                </ul>
            </div>
            <div class="content-wrap">
                <form>
                    <input type="text" name="username" value="" />
                    <input type="password" name="password" value="" />
                    <input type="button" value="Login" />
                </form>
            </div>
            <div class="footer-wrap">
                <span>Copyright &copy; 2012 - Ryan Zec
            </div>
        </div>
    </body>
</html>

现在在骨干我会与-wrap类股利是空的,为每个部分内容中的一个将在个别模板去(和每个部分可以有可能在其中显示一个以上的模板)。然后将有针对每个模板关联到将附加到正确的元素,并在其显示的模板的内容的图。

Now in backbone I would have the div with the -wrap classes be empty and to contents for each section one would go in individual templates (and each section could have more than one template that might display in it). There would then be a view associated for each template to would attach to the correct element and display the contents of the template in it.

现在用AngularJS,这是泄气到处做直接的DOM操作,除非指令。所以我想知道什么是有AngularJS,我与BackboneJS牢记这些章节的内容,需要为不同的基于内容的切换出页面/ URL他们正在查看做同样设置的最佳方法? (我知道我可以在NG-指令名称添加到div等初始加载,它加载正确,但我如何才能当页面在单页的应用程序切换它重新加载不同的数据)。

Now with AngularJS, it is discouraged to do direct DOM manipulation everywhere except in directives. So I am wondering what is the best way to have the same setup in AngularJS that I do with BackboneJS keeping in mind that the content of these sections need to be switched out for different content based on the page/url they are viewing? (I know I can add the ng-directive-name to the div so on initial load, it load correctly but how do I get it to reload to different data when the page is switched in a single page application).

推荐答案

答案是指令:)

您可以使用此 - > http://jsfiddle.net/thaqL/

you can either use this -> http://jsfiddle.net/thaqL/

或只是下载铬 - >去 http://angularjs.org - > preSS F12 - >看看他们是如何做到的。

or just download chrome -> go to http://angularjs.org -> press F12 -> check out how they did it

希望它帮助。

欢呼声

这篇关于打破HTML成AngularJS管理模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆