• 初入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
  • 相关阅读:
    Django Admin 日期字段格式化(转载)
    关于跨域请求和django处理跨域请求最佳解决方案的总结(转载)
    19.循环语句例题
    18.条件分支例题-道理:开发有两个要求:1能实现功能 2.代码最优
    17.循环语句-while循环 do while循环
    16.循环语句---for循环 for break 、for continue 、 for continue配合label写法
    15.条件?value1 : value2 三目运算符-判断语句
    14.switch case break 判断语句
    13.if 条件判断语句if 、if else
    12.经典计算题
  • 原文地址:https://www.cnblogs.com/yuluhuang/p/3500408.html
Copyright © 2020-2023  润新知