際際滷

際際滷Share a Scribd company logo
逮温厩温壊界姻庄沿岳のフレ`ムワ`クについて■

       FAGA (@Hivesbee)
粥稼乙顎鉛温姻.逮壊についてちょっとしゃべる

     FAGA (@Hivesbee)
徭失B初
? 兆念今藤腺韮
? TwitterID@Hivesbee
  ☆嗤吩な秤鵑呂弔屬笋い討い覆い任
? Web : http://nethive.info
  ☆VPSのお署をBい梨れたため唯峭嶄

? 蝶二IでPいている┐燭屬鵤芙偕芙氏繁
? ちょっとプログラムがすきな匯違繁

 2012/12/22   プログラミング伏慧僕茶氏 及19指斉郡   3
Angular.js古勣
? Javascriptのフレ`ムワ`クの匯つ
? Googleが恬撹
? MVCパタ`ンを駻

? 恷兜仝??????々とiんでしまいそうになった

書晩は階gなサンプルコ`ドをせつつ、
Angular.jsのC嬬についてしゃべっていきます

 2012/12/22   プログラミング伏慧僕茶氏 及19指斉郡   4
デ`タバインド
箭哉訌Δ靴臣念を幟肝燕幣
    <!DOCTYPE html>
                      Angular.jsアプリの傚冱
    <html ng-app>                                Angular.jsのiみzみ
      <head>
        <script src=/slideshow/angularjs/15807343/"angular.min.js"></script>
      </head>
                                                ng-modelの傚冱
      <body>
        <div>
          <input type="text" ng-model="name"><br>
          こんにちは {{ name }}
        </div>
      </body>                               ng-modelとのバインド
    </html>



 2012/12/22            プログラミング伏慧僕茶氏 及19指斉郡                       5
デ`タバインド
? {{ }} の嶄にはgな處麻しか秘らない
  猟忖双のY栽とか

? ng-modelの、鬉犬I尖を筝したいときは
  ★ng-controllerを協xし、その嶄でI尖をく




 2012/12/22   プログラミング伏慧僕茶氏 及19指斉郡   6
ng-controller
箭哉訌Δ靴臣念に鬉犬鬴陲笋錣
    <!DOCTYPE html>
    <html ng-app>
      ???                          Controller協x
      <script>
        function testCtrl($scope) {
          $scope.isFAGA = function() {
             return $scope.name == ^FAGA ̄ ? "クズ^ : $scope.name;
          }
        }                 isFAGA協x
      </script>
      <body>                                   Controller聞喘を傚冱
        <div ng-controller=^testCtrl">
          <input type="text" ng-model="name"><br>
          こんにちは {{ isFAGA() }}
        </div>
      </body>                                    isFAGAをバインド
    </html>
 2012/12/22            プログラミング伏慧僕茶氏 及19指斉郡                      7
ng-controller
採が軟きているかというと
<!DOCTYPE html>
<html ng-app>                                      Root Scope
  ???
  <script>
                                     圧aの
    function testCtrl($scope) {      傚冱
      $scope.isFAGA = function() {
         ???                                               @覚
      }
    }                                       圷ネタ
  </script>
  <body>                                           testCtrl Scope
    <div ng-controller=^testCtrl">
                                                 isFAGA : function
      <input type="text^
        ng-model="name"><br>         圧aの            name : String
      こんにちは {{ isFAGA() }}
    </div>
                                     傚冱
  </body>
</html>             Template                                  Model
 2012/12/22              プログラミング伏慧僕茶氏 及19指斉郡                       8
scope
? そのControllerが崙囮できる
  譴TemplateのDOM夛と匯崑

  C ng-controller=^testCtrl ̄ を
   傚冱したdiv坪を崙囮

  C スコ`プ坪に篳?v方を傚冱し、
    Templateに郡啌辛嬬
    ajax宥佚でもらったデ`タをtemplateに郡啌、など


 2012/12/22   プログラミング伏慧僕茶氏 及19指斉郡   9
リスト
? 云?メ`ル?etc´ を匯Eで燕幣?碧したい
  ★ng-repeat?filterでgF
    Controller
    function fooCtrl($scope) {
      $scope.array = [^A ̄, ^B ̄, ^C ̄];               JSON侘塀でd
    }

    Template
    <input type=^text ̄ ng-model=^query ̄>
    <ul ng-repeat=^item in array | filter : query ̄>
      <li> {{ item }} </li>
    </ul>

              foreach Lにng-repeatをd       碧フィルタのO協

 2012/12/22                 プログラミング伏慧僕茶氏 及19指斉郡               10
リスト
採が軟きているかというと
Controller
function fooCtrl($scope) {                             fooCtrl Scope
  $scope.array = [^A ̄,^B ̄,^C ̄];                         array : array
}
                                      圷ネタ              query : String


                                                                @覚

                                                     Repeater Scope
Template                                              Repeater Scope
                                                      item : String
                                                        Repeater Scope
<input type=^text ̄ ng-model=^query ̄>                    item : String
<ul ng-repeat=^item in array | filter : query ̄>           item : String
  <li> {{ item }} </li>
</ul>
                                                                    Model
  2012/12/22                 プログラミング伏慧僕茶氏 及19指斉郡                        11
ル`ティング
? 鮫中の俳り紋え
Template
<!DOCTYPE html>
<html ng-app="demo">          ng-appに兆念が原いた
  <head>
    <script src=/slideshow/angularjs/15807343/"js/angular.min.js"></script>
    <script src=^js/app.js ̄></script>
</head>
                                      ル`ティング喘javascript
  <script>
    function ACtrl($scope) {}
    function BCtrl($scope) {}
  </script>
  <body>
    <a href="#/A">Aへ</a><br>
    <a href="#/B">Bへ</a><br>        ng-viewの奉來弖紗
    <div ng-view></div>        ☆この嶄で鮫中が俳り紋わる
  </body>
</html>
  2012/12/22         プログラミング伏慧僕茶氏 及19指斉郡                12
ル`ティング
? 鮫中の俳り紋え
                ng-app兆を峺協

app.js
angular.module("demo", []).
     config(["$routeProvider", function($routeProvider) {
        $routeProvider.
          when(^/A", {templateUrl : "A.html", controller : ACtrl}).
          when(^/B", {templateUrl : "B.html", controller : BCtrl}).
          otherwise({redirectTo : "/A"});
   }]);

                  whenで屎械rの鮫中w卞、
               otherwiseでwhere參翌の鮫中w卞

                                         A.htmlとB.htmlは恬撹gみとします
  2012/12/22           プログラミング伏慧僕茶氏 及19指斉郡                     13
ほかにも
? 鏡徭のタグ伏撹
  ★ 何瞳として函りQうことが辛嬬

? e2e-testing
  ★ SにAngular.jsのシナリオテストができる




 2012/12/22   プログラミング伏慧僕茶氏 及19指斉郡   14
まとめ
? コ`ド楚が富なくても薦なアプリ_k辛嬬
? TemplateとControllがDOM夛で
  匯崑しているため岷湖議に尖盾しやすい
? ル`ティングが蛍かりやすすぎて湖

? htmlに鏡徭奉來が岱羨するため丘森があるかも
? 晩云Zリファレンスはよ



 2012/12/22   プログラミング伏慧僕茶氏 及19指斉郡   15

More Related Content

粥稼乙顎鉛温姻.逮壊についてちょっとしゃべる

  • 3. 徭失B初 ? 兆念今藤腺韮 ? TwitterID@Hivesbee ☆嗤吩な秤鵑呂弔屬笋い討い覆い任 ? Web : http://nethive.info ☆VPSのお署をBい梨れたため唯峭嶄 ? 蝶二IでPいている┐燭屬鵤芙偕芙氏繁 ? ちょっとプログラムがすきな匯違繁 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 3
  • 4. Angular.js古勣 ? Javascriptのフレ`ムワ`クの匯つ ? Googleが恬撹 ? MVCパタ`ンを駻 ? 恷兜仝??????々とiんでしまいそうになった 書晩は階gなサンプルコ`ドをせつつ、 Angular.jsのC嬬についてしゃべっていきます 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 4
  • 5. デ`タバインド 箭哉訌Δ靴臣念を幟肝燕幣 <!DOCTYPE html> Angular.jsアプリの傚冱 <html ng-app> Angular.jsのiみzみ <head> <script src=/slideshow/angularjs/15807343/"angular.min.js"></script> </head> ng-modelの傚冱 <body> <div> <input type="text" ng-model="name"><br> こんにちは {{ name }} </div> </body> ng-modelとのバインド </html> 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 5
  • 6. デ`タバインド ? {{ }} の嶄にはgな處麻しか秘らない 猟忖双のY栽とか ? ng-modelの、鬉犬I尖を筝したいときは ★ng-controllerを協xし、その嶄でI尖をく 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 6
  • 7. ng-controller 箭哉訌Δ靴臣念に鬉犬鬴陲笋錣 <!DOCTYPE html> <html ng-app> ??? Controller協x <script> function testCtrl($scope) { $scope.isFAGA = function() { return $scope.name == ^FAGA ̄ ? "クズ^ : $scope.name; } } isFAGA協x </script> <body> Controller聞喘を傚冱 <div ng-controller=^testCtrl"> <input type="text" ng-model="name"><br> こんにちは {{ isFAGA() }} </div> </body> isFAGAをバインド </html> 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 7
  • 8. ng-controller 採が軟きているかというと <!DOCTYPE html> <html ng-app> Root Scope ??? <script> 圧aの function testCtrl($scope) { 傚冱 $scope.isFAGA = function() { ??? @覚 } } 圷ネタ </script> <body> testCtrl Scope <div ng-controller=^testCtrl"> isFAGA : function <input type="text^ ng-model="name"><br> 圧aの name : String こんにちは {{ isFAGA() }} </div> 傚冱 </body> </html> Template Model 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 8
  • 9. scope ? そのControllerが崙囮できる 譴TemplateのDOM夛と匯崑 C ng-controller=^testCtrl ̄ を 傚冱したdiv坪を崙囮 C スコ`プ坪に篳?v方を傚冱し、 Templateに郡啌辛嬬 ajax宥佚でもらったデ`タをtemplateに郡啌、など 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 9
  • 10. リスト ? 云?メ`ル?etc´ を匯Eで燕幣?碧したい ★ng-repeat?filterでgF Controller function fooCtrl($scope) { $scope.array = [^A ̄, ^B ̄, ^C ̄]; JSON侘塀でd } Template <input type=^text ̄ ng-model=^query ̄> <ul ng-repeat=^item in array | filter : query ̄> <li> {{ item }} </li> </ul> foreach Lにng-repeatをd 碧フィルタのO協 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 10
  • 11. リスト 採が軟きているかというと Controller function fooCtrl($scope) { fooCtrl Scope $scope.array = [^A ̄,^B ̄,^C ̄]; array : array } 圷ネタ query : String @覚 Repeater Scope Template Repeater Scope item : String Repeater Scope <input type=^text ̄ ng-model=^query ̄> item : String <ul ng-repeat=^item in array | filter : query ̄> item : String <li> {{ item }} </li> </ul> Model 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 11
  • 12. ル`ティング ? 鮫中の俳り紋え Template <!DOCTYPE html> <html ng-app="demo"> ng-appに兆念が原いた <head> <script src=/slideshow/angularjs/15807343/"js/angular.min.js"></script> <script src=^js/app.js ̄></script> </head> ル`ティング喘javascript <script> function ACtrl($scope) {} function BCtrl($scope) {} </script> <body> <a href="#/A">Aへ</a><br> <a href="#/B">Bへ</a><br> ng-viewの奉來弖紗 <div ng-view></div> ☆この嶄で鮫中が俳り紋わる </body> </html> 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 12
  • 13. ル`ティング ? 鮫中の俳り紋え ng-app兆を峺協 app.js angular.module("demo", []). config(["$routeProvider", function($routeProvider) { $routeProvider. when(^/A", {templateUrl : "A.html", controller : ACtrl}). when(^/B", {templateUrl : "B.html", controller : BCtrl}). otherwise({redirectTo : "/A"}); }]); whenで屎械rの鮫中w卞、 otherwiseでwhere參翌の鮫中w卞 A.htmlとB.htmlは恬撹gみとします 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 13
  • 14. ほかにも ? 鏡徭のタグ伏撹 ★ 何瞳として函りQうことが辛嬬 ? e2e-testing ★ SにAngular.jsのシナリオテストができる 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 14
  • 15. まとめ ? コ`ド楚が富なくても薦なアプリ_k辛嬬 ? TemplateとControllがDOM夛で 匯崑しているため岷湖議に尖盾しやすい ? ル`ティングが蛍かりやすすぎて湖 ? htmlに鏡徭奉來が岱羨するため丘森があるかも ? 晩云Zリファレンスはよ 2012/12/22 プログラミング伏慧僕茶氏 及19指斉郡 15