• AngularJS Best Practices: ngRoute


    app/
    ----- components/
    ---------- users/
    --------------- controllers/
    -------------------- users.controller.js
    --------------- views/
    -------------------- user-list.tpl.html
    --------------- app.users.js
    --------------- app.users.routes.js
    ---------- roles/
    --------------- controllers/
    -------------------- roles.controller.js
    --------------- views/
    -------------------- role-list.tpl.html
    --------------- app.roles.js
    --------------- app.roles.routes.js
    ----- app.js
    assets/
    ----- libs/
    ---------- angular/
    index.html

    index.html

    <!DOCTYPE html>
    <html ng-app="app">
        <head>
            <title></title>
            <meta charset="utf-8" />
        </head>
        <body>
            <ul>
                <li>
                    <a href="#/users">Users</a>
                </li>
                <li>
                    <a href="#/roles">Roles</a>
                </li>
            </ul>
    
            <ng-view></ng-view>
    
            <script type="text/javascript" src="/assets/libs/angular/angular.min.js"></script>
            <script type="text/javascript" src="/assets/libs/angular/angular-route.min.js"></script>
            <script type="text/javascript" src="/app/app.js"></script>
            <script type="text/javascript" src="/app/components/users/app.users.js"></script>
            <script type="text/javascript" src="/app/components/users/app.users.routes.js"></script>
            <script type="text/javascript" src="/app/components/users/controllers/user.controller.js"></script>
            <script type="text/javascript" src="/app/components/roles/app.roles.js"></script>
            <script type="text/javascript" src="/app/components/roles/app.roles.routes.js"></script>
            <script type="text/javascript" src="/app/components/roles/controllers/role.controller.js"></script>
        </body>
    </html>

    app.js

    (function() {
        'use strict';
    
        angular
            .module('app', ["app.users",
                "app.roles"
            ]);
    
    })();

    app.users.js

    (function() {
        'use strict';
    
        angular
            .module('app.users', [
                'ngRoute'
            ]);
    
    })();

    app.users.routes.js

    (function() {
        'use strict';
    
        angular
            .module('app.users')
            .config(['$routeProvider', function($routeProvider) {
                $routeProvider.
                    when('/users', {
                        templateUrl: '/app/components/users/views/user-list.tpl.html',
                        controller: 'UserController'
                    });
            }]);
    
    })();

    user-list.tpl.html

    <h2>Users</h2>

    user.controller.js

    (function() {
        'use strict';
    
        angular
            .module('app.users')
            .controller('UserController', function() {
            });
    
    })();

    The "use strict" Directive

    The "use strict" directive is new in JavaScript 1.8.5 (ECMAScript version 5).

    It is not a statement, but a literal expression, ignored by earlier versions of JavaScript.

    The purpose of "use strict" is to indicate that the code should be executed in "strict mode".

    With strict mode, you can not, for example, use undeclared variables.

  • 相关阅读:
    java 13-6 Char的包装类Character
    java13-5 JDK1.5以后的一个新特性和Integer的面试题
    java 13-4 Integer和String、int之间的转换,进制转换
    java 13-3 int类型的包装包Integer
    java 13-2 Arrays工具类
    java 13-1 数组高级二分查找
    java12
    kafka语句示例
    zookeeper安装
    redhat java配置
  • 原文地址:https://www.cnblogs.com/zhangpengc/p/5009002.html
Copyright © 2020-2023  润新知