zoukankan      html  css  js  c++  java
  • 初入angularJS [4]

    index.html

     1 <!DOCTYPE html>
     2 <html ng-app="demoApp">
     3 <head>
     4     <title>Using Angular JS Directives and Data Binging</title>
     5     <script src="./angular-1.0.1.min.js"></script>
     6 </head>
     7 <body>
     8 <div>
     9     <!-- Placeholder for views-->
    10     <div ng-view=""></div>
    11 </div>
    12 <script>
    13     var demoApp = angular.module("demoApp", []);
    14 
    15 
    16     demoApp.config(function ($routeProvider) {
    17         $routeProvider
    18                 .when('/view1', {
    19                     controller: 'SimpleController',
    20                     templateUrl: 'view1.html'
    21                 })
    22                 .when('/view2', {
    23                     controller: "SimpleController",
    24                     templateUrl: 'view2.html'
    25                 })
    26                 .otherwise({redirectTo: '/view1'});
    27     });
    28 
    29     demoApp.factory('simpleFactory', function () {
    30         var customers = [
    31             {name: 'John Smith', city: 'Phoenix'},
    32             {name: 'John Doe', city: 'New York'},
    33             {name: 'Jane Doe', city: 'San Francisco'}
    34         ];
    35         var factory = {};
    36         factory.getCustomers = function () {
    37             return customers;
    38         };
    39         factory.postCustomer = function (customer) {
    40         };
    41         return factory;
    42     });
    43 
    44     demoApp.controller('SimpleController', function ($scope,simpleFactory) {
    45         $scope.customers =[];
    46         init();
    47         function init(){
    48             $scope.customers = simpleFactory.getCustomers();
    49             console.info( $scope.customers );
    50         }
    51 
    52         $scope.addCustomer = function () {
    53             $scope.customers.push(
    54                     {
    55                         name: $scope.newCustomer.name,
    56                         city: $scope.newCustomer.city
    57                     });
    58         };
    59     });
    60 </script>
    61 
    62 </body>
    63 </html>
    View Code

    view1

     1 <div class="container" >
     2     <h2>View 1</h2>
     3     Name:
     4     <br/>
     5     <input type="text" ng-model="filter.name"/>
     6     <br/>
     7     <ul>
     8         <li ng-repeat="cust in customers | filter:filter.name | orderBy:filter.name">{{cust.name}}</li>
     9     </ul>
    10     <br/>
    11     Customer Name:<br/>
    12     <input type="text" ng-model="newCustomer.name"/>
    13     <br/>
    14     Customer City:<br/>
    15     <input type="text" ng-model="newCustomer.city" /><br/>
    16     <button ng-click="addCustomer()">Add Customer</button>
    17     <br/>
    18     <a href="#/view2">View 2</a>
    19 </div>
    View Code

    view2

     1 <!DOCTYPE html>
     2 <html ng-app="demoApp">
     3 <head>
     4     <title></title>
     5     <script src="./angular-1.0.1.min.js"></script>
     6 </head>
     7 <body>
     8 <div>
     9     Name:<br/>
    10     <input type="text" ng-model="name" /><br/>
    11     <ul>
    12         <li ng-repeat="cust in customers | filter:name | orderBy:'name'">{{cust.name}}</li>
    13 
    14     </ul>
    15 </div>
    16 
    17 </body>
    18 </html>
    View Code
  • 相关阅读:
    10 大排序算法总结
    什么是堆和栈
    8张思维导图学习javascript
    Service Locator 模式
    Unity系列文章
    IoC模式(依赖、依赖倒置、依赖注入、控制反转)
    ASP.NET应用程序与页面生命周期
    TCP/IP网络协议的通俗理解,SOCKET,HTTP,SOAP
    部分计算机上视频不能自动刷新的解决方案
    数梦工场Java实习面试(offer到手含面试经验及答案)
  • 原文地址:https://www.cnblogs.com/yuluhuang/p/3500408.html
Copyright © 2011-2022 走看看