zoukankan      html  css  js  c++  java
  • angular 入门

    入门

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script type="text/javascript" src="js/angular.min.js"></script>
        </head>
        
        <body ng-app>
            {{100+100}}
        </body>
    </html>

    双向绑定

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script type="text/javascript" src="js/angular.min.js"></script>
        </head>
        <body ng-app>
            喜欢谁
            <input type="text" ng-model="myname" />
            喜欢{{myname}}
        </body>
    </html>

     初始化值1

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script type="text/javascript" src="js/angular.min.js"></script>
        </head>
        <body>
            <body ng-app ng-init="myname='proyuan'">
                请输入你的姓名:<input ng-model="myname">
                你的名字是{{myname}}
            </body>
        </body>
    </html>

     两数相加

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script type="text/javascript" src="js/angular.min.js"></script>
            <script>
                var app=angular.module('MyApp',[])
                app.controller('mycontroller',function($scope){
                    $scope.add=function(){
                        return parseInt($scope.x)+parseInt($scope.y)
                    }
                });
            </script>
        </head>
        <body ng-app='MyApp' ng-controller='mycontroller'>
            <!--ng-controller为程序添加控制器-->
            x:<input ng-model="x" />
            y:<input ng-model="y" />
            结果{{add()}}
        </body>
    </html>
    View Code

    点击事件

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script type="text/javascript" src="js/angular.min.js"></script>
            <script>
                var app=angular.module('MyApp',[])
                app.controller('mycontroller',function($scope){
                    $scope.add=function(){
                        $scope.z=parseInt($scope.x)+parseInt($scope.y)
                    }
                });
            </script>
        </head>
        <body ng-app='MyApp' ng-controller='mycontroller'>
            <!--ng-controller为程序添加控制器-->
            x:<input ng-model="x" />
            y:<input ng-model="y" />
            <button ng-click="add()">点击</button>
            结果{{z}}
        </body>
    </html>
    View Code

     

     循环数组(注意集合不能重复...)

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            
            <script type="text/javascript" src="js/angular.min.js"></script>
            <script>
                var app = angular.module('myApp',[])
                app.controller('mycontroller',function($scope){
                    $scope.list=[66,87,43,32,08];
                });
            </script>
        </head>
        <body ng-app="myApp" ng-controller="mycontroller">
            <table>
                <tr ng-repeat="x in list">
                    <td>{{x}}</td>
                </tr>
            </table>
        </body>
    </html>
    View Code

     循环数组对象

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script type="text/javascript" src="js/angular.min.js"></script>
            <script>
                var app=angular.module('MyApp',[])
                app.controller('mycontroller',function($scope){
                    $scope.list=[
                        {name:'sx',address:'保定',tel:1515},
                        {name:'xy',address:'保定',tel:1515},
                        {name:'sy',address:'保定',tel:1515}
                    ]
                });
            </script>
        </head>
        <body ng-app="MyApp" ng-controller="mycontroller">
            <table>
                <tr>
                    <td>姓名</td>
                    <td>地址</td>
                    <td>电话</td>
                </tr>
                <tr ng-repeat="entity in list">
                    <td>{{entity.name}}</td>
                    <td>{{entity.address}}</td>
                    <td>{{entity.tel}}</td>
                </tr>
            </table>
            
        </body>
    </html>
    View Code

  • 相关阅读:
    .NET的委托和匿名函数应用一例
    C#中,变量前的@符号
    ExtJs中多个form情况下指定某个form使能
    【Python web 开发】个人中心-用户收藏功能
    【Python web 开发】用户个人信息修改
    【Python web 开发】django rest framwork 动态设置serializers
    【Python web 开发】django rest framwork动态设置权限premission
    【fiddler】用fiddler 拦截请求修改response 回包测试
    【Python web 开发】联合唯一索引
    【Python web 开发】用户收藏功能
  • 原文地址:https://www.cnblogs.com/proyuan/p/11847894.html
Copyright © 2011-2022 走看看