AngularJS学习(一)

时间:2014-08-07 12:49:20   收藏:0   阅读:196

1、HelloWorld篇

  1.1 环境

    下载:angular-1.2.5min.js

  1.2 源代码

<!doctype html>
<html ng-app>
    <head>
        <script src="angular-1.2.5.min.js"></script>
    </head>
    <body>
        hello {{‘world‘}}!
    </body>
<html

  1.3 运行结果

  bubuko.com,布布扣

2、双向数据绑定

  2.1 源代码

<!doctype html>
<html ng-app>
    <head>
        <script src="angular-1.2.5.min.js"></script>
    </head>
    <body>
        Your name:<input type="text" ng-model="yourname" placeholder="world">
        <hr>
        hello {{yourname || ‘world‘}}!
    </body>
<html

  2.2 运行结果

  bubuko.com,布布扣

  2.3、说明

    文本输入指令<input ng-model="yourname"/> 绑定一个叫yourname的模型变量

    双大括号标记yourname模型变量添加到问候语文本。

    你不需要为改应用另外注册一个事件监听器或添加事件处理程序!

    现在试着在输入框中输入您的名称,您键入的名称将立即更新显示在问候语中,这就是AngularJs的双向绑定概念。输入框的任何更改都会立即反应到模型变量(一个方向)模型变量的任何更改都会立即反映到问候语文本中(另一个方向)

  

 

AngularJS学习(一),布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!