angularJS简介和几个重要的例子

来源:互联网 发布:网络链接不上 编辑:程序博客网 时间:2024/04/30 02:22
angularJS是通过指令来扩展html,并且通过表达式来绑定到html页面。
都有哪些指令?  ng-model ,ng-app  ng-bind等等
表达式是什么?  {{*****}}



这里提供一个免费的angularJS的框架地址
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>


举一个栗子:
初始化数据的方法

<div ng-app="" ng-init="firstName='John'">
 
<p>姓名为 <span ng-bind="firstName"></span></p>
 
</div>


注意点:
1 初始化不是ng-init写在某个标签中
2 如果不用表达式{{****}},可以用ng-bind来代替。
AngularJS 表达式把数据绑定到 HTML,这与 ng-bind 指令有异曲同工之妙。




表达式中可以有数字的计算:
比如{{ 5 + 5 }}



angularJS中“同步”显示数据的例子中,还可以针对数据进行<script></script>内的重新定义。
举个例子:
<div ng-app="myApp" ng-controller="myCtrl">
 
名: <input type="text" ng-model="firstName"><br>
姓: <input type="text" ng-model="lastName"><br>
<br>
姓名: {{firstName + " " + lastName}}
 
</div>
 
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.firstName= "John";
    $scope.lastName= "Doe";
});
</script>


注意点:
在<script></script>中,调用的话,需要对angularJS模块进行引用,比如:
var app = angular.module('myApp', []);
原创粉丝点击