Breaking HTML into management templates for Angula

2019-06-07 21:52发布

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>

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.

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).

2条回答
一夜七次
2楼-- · 2019-06-07 22:22

I think for the time being the best answer is ngInclude. I think that the AngularJS team wants to make routes more powerful (based on something I remember reading) in the future (like multiple views per route where each should should have a controller for the header, a controller for the footer, and a controller for the main content) but until then ngInclude should hopefully get me by.

查看更多
迷人小祖宗
3楼-- · 2019-06-07 22:38

Answer is directives :)

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

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

hope it helps.

cheers

查看更多
登录 后发表回答