AngularJS继续中

<html ng-app>//全局中引用对应于PhoneListCtrl 模板

<head>
    <script src="js/angular.js"></script>
    <script src="js/test.js"></script>
</head>

<body ng-controller="PhoneListCtrl">


    <ul>
        <li ng-repeat="pho in phones">
            {{pho.name}}
            <p>{{pho.snippet}}</p>
        </li>
    </ul>

//div里面的作用域 myapp <div ng-app="myapp" ng-controller="mytest"> <ul> <li ng-repeat="ph in phone"> {{ph.name}} <p>{{ph.snippet}}</p> </li> </ul> </div> </body> </html>

js 代码

function PhoneListCtrl($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."
      }
    ];
}


//自己声明模板 共外部使用
var app = angular.module(‘myapp‘, []);
app.controller(‘mytest‘, function ($scope) {
    $scope.phone = [
       {
           "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."
       }
    ];
});

http://www.widuu.com/archives/04/1035.html

http://www.ituring.com.cn/article/15762

尚未顿悟

AngularJS继续中,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。