<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                現在,我們有了`phone-list`和`hello-yunzhi`兩個組件,都存在于`phone-list.component.js`中。顯然,這有一點問題。因為我們的`hello-yunzhi`組件,更愿意有自己的專屬文件----`hello-yunzhi.component.js`。 下面,讓我們共同規劃下這兩個組件。 規劃組件以前,我們在根目錄下,新建`yun-zhi`文件夾,用以存放`hell-yunzhi`及`phone-list`組件。文件夾建立后,將`phone-list.component.js`移動到此文件夾。 移動后,目錄結構如下: ~~~ . ├── app.js ├── bower_components │?? └── angular │?? ├── LICENSE.md │?? ├── README.md │?? ├── angular-csp.css │?? ├── angular.js │?? ├── angular.min.js │?? ├── angular.min.js.gzip │?? ├── angular.min.js.map │?? ├── bower.json │?? ├── index.js │?? └── package.json ├── index.html ├── test.html └── yun-zhi └── phone-list.component.js ~~~ ## 剝離`hello-yunzhi`組件 新建 `hello-yunzhi.component.js` 代碼如下: ~~~ // 定義一個yunZhi模塊,供組件使用。 angular.module('yunZhi', []); // 在yunzhi模塊上注冊'helloYunzhi'組件 angular. module('yunZhi'). component('helloYunzhi', { template:'<h2>Hello Yunzhi</h2>', }); ~~~ 同時,刪除`phone-list.component.js`中關于組件`hello-yunzhi`的定義。 ## 重新引用`hello-yunzhi`、`phone-list` `index.html` ~~~ ... <head> <meta charset="UTF-8"> <title>hello</title> <script src="bower_components/angular/angular.js"></script> <script src="app.js"></script> <script src="yun-zhi/phone-list.component.js"></script> <script src="yun-zhi/hello-yunzhi.component.js"></script> </head> ... ~~~ 測試: ![](https://box.kancloud.cn/2016-07-20_578f3934742da.png) ## 重構 盡量不去制造重復的輪子。 通過觀察代碼,我們發現,在兩個組件中,存在重復的輪子,即對yunZhi模塊的定義。 現在,我們新增一個文件,專門來進行模塊的定義,去掉一個重復的輪子。 `yun-zhi/yun-zhi.module.js` ~~~ // 定義一個yunZhi模塊,供組件使用。 angular.module('yunZhi', []); ~~~ 然后去掉兩個組件中上面的代碼,并在index.html中引用我們剛剛建立的`yun-zhi.module.js` `index.html` ~~~ <head> <meta charset="UTF-8"> <title>hello</title> <script src="bower_components/angular/angular.js"></script> <script src="app.js"></script> <script src="yun-zhi/yun-zhi.module.js"></script> <script src="yun-zhi/phone-list.component.js"></script> <script src="yun-zhi/hello-yunzhi.component.js"></script> </head> ~~~ ![](https://box.kancloud.cn/2016-07-20_578f393494bff.png) 沒錯,效果仍然不變。 * * * * * 各文件代碼如下: `app.js` ~~~ // 定義模塊 var phonecatApp = angular.module('phonecatApp', ['yunZhi']); // 定義控制器 phonecatApp.controller('PhoneListController', function($scope) { $scope.phones = [{ name: 'Nexus S', snippet: 'Fast just got faster with Nexus S.' }, { name: 'Motorola XOOM? with Wi-Fi', snippet: 'The Next, Next Generation tablet.' }, { name: 'MOTOROLA XOOM?', snippet: 'The Next, Next Generation tablet.' }]; }); ~~~ `yun-zhi/yun-zhi.module.js` ~~~ // 定義一個yunZhi模塊,供組件使用。 angular.module('yunZhi', []); ~~~ `yun-zhi/hello-yunzhi.component.js' ~~~ // 在yunzhi模塊上注冊'helloYunzhi'組件 angular. module('yunZhi'). component('helloYunzhi', { template:'<h2>Hello Yunzhi</h2>', }); ~~~ `yun-zhi/phone-list.components.js` ~~~ angular. module('yunZhi'). component('phoneList', { template: '<ul>' + '<li ng-repeat="phone in $ctrl.phones">' + '<span>{{phone.name}}</span>' + '<p>{{phone.snippet}}</p>' + '</li>' + '</ul>', controller: function PhoneListController() { this.phones = [{ name: 'Nexus S', snippet: 'Fast just got faster with Nexus S.' }, { name: 'Motorola XOOM? with Wi-Fi', snippet: 'The Next, Next Generation tablet.' }, { name: 'MOTOROLA XOOM?', snippet: 'The Next, Next Generation tablet.' }]; } }); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看