国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

angularJS 入門基礎

2019-11-20 13:11:46
字體:
來源:轉載
供稿:網友

angular   

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

復制代碼 代碼如下:

.angular的數據綁定實例,這個是最基礎的,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 src="
>
    <link href="
    <script src="</head>
<body ng-app="app">
    <script type="text/javascript">
           var app = angular.module("app",[]);
    </script>
    <div class="panel panel-default">
        <div class="panel-heading">
            通過angular,展示數組對應的數據;
        </div>
        <div class="panel-body">
            <div id="arr-bind" 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:

復制代碼 代碼如下:

.factory工廠, $provider, service等等都是一樣樣的, 不要感覺很難, 其實就是看出一個數據模型或者實例就好了;:

復制代碼 代碼如下:

<!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 src="
>
    <link href="
    <script src="</head>
<body ng-app="app">
    <script type="text/javascript">
           var app = angular.module("app",[]);
    </script>
    <div id="factory" class="panel panel-default">
        <div class="panel-heading">
            angular中的factory就相當于一個公用的實例方法,可以理解為一個多個控制器都可以用的函數;
        </div>
        <div  class="panel-body" ng-controller="factory">
            {{json}}
            <script>
                app.factory("ff", function() {
                    return {
                        "noting" : "json"
                    };
                });
                app.controller("factory", function($scope, ff) {
                    $scope.json = ff;
                });
            </script>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-title">
            angular的指令;
        </div>
        <div class="panel-body">
            <heh>do you content for?</heh>
            <script>
                app.directive("heh", function() {
                    return {
                        restrict : "AE",
                        replace : true,
                        transclude : true,
                        template : '<div> <button class="btn-danger" ng-transclude></button></div>'
                    };
                })
            </script>
        </div>
    </div>

</body>
</html>

.ng-switch指令的使用(這個跟模板很想的,就是我們常見的點擊隱藏和顯示Tab插件的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 src="
>
    <link href="
    <script src="</head>
<body ng-app="app">
    <script type="text/javascript">
           var app = angular.module("app",[]);
    </script>
    <div class="panel panel-default">
        <div class="panel-heading">
            ng-switch的使用
        </div>
        <div class="panel-body" ng-controller="sw">
            <div ng-init="a=2">
                <ul ng-switch on="a">
                    <li ng-switch-when="1">1</li>
                    <li ng-switch-when="2">2</li>
                    <li ng-switch-default>other</li>
                </ul>
              </div>
              <div>
                  <button ng-click="a=1" class="btn btn-primary">test</button>
                  <button ng-click="a=2" class="btn btn-info">test</button>     
                  <button ng-click="a=3" class="btn btn-warning">test</button>
              </div>
        </div>
        <script type="text/javascript">
            app.controller("sw", function($scope) {
            });
        </script>
    </div>
</body>
</html>

ng-src和ng-href;

復制代碼 代碼如下:

如何操作頁面的樣式,這個直接改綁定的數據模型就好了:

復制代碼 代碼如下:

    <div class="panel panel-default">
        <div class="panel-heading">
            angular對樣式進行操作;(jQ是手動選擇元素對元素樣式進行操作,angular提供了一種更 主站蜘蛛池模板: 张家口市| 林西县| 资源县| 北流市| 姚安县| 志丹县| 台江县| 晋州市| 积石山| 庄浪县| 武鸣县| 临潭县| 兴义市| 张北县| 夏津县| 金山区| 独山县| 织金县| 广东省| 临沧市| 同江市| 彰武县| 湖州市| 河津市| 和龙市| 青神县| 黎城县| 连云港市| 綦江县| 新田县| 贵港市| 峨山| 青海省| 南通市| 东丰县| 循化| 凤台县| 新巴尔虎右旗| 静海县| 理塘县| 车致|