码迷,mamicode.com
首页 > 其他好文 > 详细

angular

时间:2016-06-27 17:11:46      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

Demo1:简介

ng-app ng-model 

技术分享
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

    <div ng-app="">
        <p>名字:<input type="text" ng-model="name"></p>
        <h1>Hello {{name}}</h1>
    </div>

</body>
</html>
View Code

ng-bind  ng-init

技术分享
<!-- ng-init 指令初始化 AngularJS 应用程序变量
ng-bind 指令把应用程序变量 name 绑定到某个段落的 innerHTML
div要包含住ng-app,否则ng元素失效 -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> 
</head>
<body>
    <div ng-app="" ng-init="firstName=‘John‘">

    <p>姓名为:<span ng-bind="firstName"></span></p>
    </div>
</body>
</html>
View Code

Module Controller  用汉字才能对齐,用英文就丑了

技术分享
<!-- AngularJS 模块(Module) 定义了 AngularJS 应用。
AngularJS 控制器(Controller) 用于控制 AngularJS 应用。
ng-app指令定义了应用, ng-controller 定义了控制器。 -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> 
</head>
<body>
    <p>尝试修改以下表单。</p>

    <div ng-app="myApp" ng-controller="myCtrl">
        姓: <input type="text" ng-model="lastName"><br>
        名:  <input type="text" ng-model="firstName"><br><br>
        name: {{firstName +" "+ lastName}}
    </div>

    <script>
        var app = angular.module(‘myApp‘, []);
        app.controller(‘myCtrl‘, function($scope) {
            $scope.firstName = ‘John‘;
            $scope.lastName = ‘Doe‘;
        })
    </script>
</body>
</html>
View Code

Demo2:指令

ng-repeat

技术分享
<!-- ng-repeat 指令会重复一个 HTML 元素 -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> 
</head>
<body>
    <div data-ng-app="" data-ng-init="names=[‘tab‘, ‘ctrl‘, ‘shift‘]">
        <ul>
            <li data-ng-repeat="x in names">
                {{x}}
            </li>
        </ul>
    </div>
</body>
</html>
View Code

directive自定义指令

技术分享
<!-- angular.module小写
restrict 值可以是以下几种:
E 只限元素名使用
A 只限属性使用
C 只限类名使用
M 只限注释使用
restrict写在template同样的位置 -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> 
</head>
<body ng-app="myApp">
    <miao-directive></miao-directive>
    <script>
        var myApp = angular.module(‘myApp‘, []);
        myApp.directive(‘miaoDirective‘, function() {
            return {template: ‘<h1>自定义指令!</h1>‘};
        });
    </script>
</body>
</html>
View Code

 

angular

标签:

原文地址:http://www.cnblogs.com/tabCtrlShift/p/5620369.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!