angularJS 入门基础

所有用到的库, 全部用的CDN:

复制代码 代码如下:


    <script src=""></script>
    <script src=""></script>
    <link href="">
    <script src="" type="text/javascript"></script>

.angular的数据绑定实例,这个是最基础的,angular的所有枝叶全部从这里开始:.

复制代码 代码如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <script src=""></script>
    <script src=""></script>
    <link href="">
    <script src="" type="text/javascript"></script>
</head>
<body ng-app="app">
    <script type="text/javascript">
           var app = angular.module("app",[]);
    </script>
    <div>
        <div>
            angular最强大的东西,数据的绑定binding
        </div>
        <div>
            <div ng-controller="bf">
                <input type="text" ng-model="data" />
                {{data}}
                <script>
                    app.controller("bf", function($scope) {
                        $scope.data = "testData";
                        //$scope.$apply();
                    });
                </script>
            </div>
        </div>
    </div>
</body>
</html>

通过angular,展示数组对应的数据;.

复制代码 代码如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <script src=""></script>
    <script src=""></script>
    <link href="">
    <script src="" type="text/javascript"></script>
</head>
<body ng-app="app">
    <script type="text/javascript">
           var app = angular.module("app",[]);
    </script>
    <div>
        <div>
            通过angular,展示数组对应的数据;
        </div>
        <div>
            <div ng-app="arr-app" ng-controller="arrCon">
                <style>
                    .s{
                        color:#f00;
                    }
                    li{
                        cursor: pointer;
                    }
                </style>
                <ul>
                    <li ng-repeat="i in lists" ng-click="bered($index)" ng-class="{s : $index == flag}">
                        {{i.name}}----{{i.age}}
                    </li>
                </ul>
                <script>
                    //angular.module("arr-app", []);
                    function arrCon($scope) {
                        $scope.flag = 0;
                        $scope.bered = function(i) {
                            $scope.flag = i;
                        };
                        $scope.lists = [
                            {name : "hehe",
                                age:10},
                            {
                                name : "xx",
                                age : 20
                            },
                            {
                                name : "yy",
                                age : 2
                            },
                            {
                                name : "jj",
                                age : 220
                            }
                        ]
                    };
                </script>
            </div>
        </div>
    </div>
</body>
</html>

.数据过滤器的DEMO:

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgfxjj.html