Basics of getting started with angularJS_AngularJS
angularjs
Getting Started Basics
angular
All libraries used, all CDNs used:
Copy code The code is as follows:
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
.angular data binding example, this is the most basic, all branches and leaves of angular start from here:.
Copy code The code is as follows:
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
angular最强大的东西,数据的绑定binding
{{data}}
<script><br> app.controller("bf", function($scope) {<br> $scope.data = "testData";<br> //$scope.$apply();<br> });<br> </script>
通过angular,展示数组对应的数据;.
复制代码 代码如下:
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
通过angular,展示数组对应的数据;
{{i.name}}----{{i.age}}
<script><br> //angular.module("arr-app", []);<br> function arrCon($scope) {<br> $scope.flag = 0;<br> $scope.bered = function(i) {<br> $scope.flag = i;<br> };<br> $scope.lists = [<br> {name : "hehe",<br> age:10},<br> {<br> name : "xx",<br> age : 20<br> },<br> {<br> name : "yy",<br>Age: 2<br> Name: "jj",<br> Age: 220<br> } ]<br> };<br> </div><br> </body><br> </html><br> <br><br> <br>.DEMO of data filter: <br> <br><br> </div> <p>Copy code</p> <p></p> <div class="codetitle"> The code is as follows:<span><div class="codebody" id="code19833"> <br> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"><br> <html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>"><br> <head><br> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br> <title>angular</title><br> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><br> <script src="<a href="http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script">http://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script</a>><br> <script src="<a href="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script">http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js"></script</a>><br> <link href="<a href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css">http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css</a>" rel="stylesheet"><br> <script src="<a href="http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js">http://cdn.bootcss.com/underscore.js/1.7.0/underscore-min.js</a>" type="text/javascript"></script>
数据过滤器;
{{sourCode}}
{{sourCode | up}}
<script><br> function filte($scope) {<br> $scope.sourCode = "hehe lala dudu oo zz";<br> };<br> app.filter("up" ,function() {<br> return function(ipt) {<br> return ipt.replace(/ (w)/g,function($0,$1) {<br> return " " $1.toUpperCase();<br> });<br> }<br> });<br> </script>
.factory工厂, $provider, service等等都是一样样的, 不要感觉很难, 其实就是看出一个数据模型或者实例就好了;:
复制代码 代码如下:
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
angular中的factory就相当于一个公用的实例方法,可以理解为一个多个控制器都可以用的函数;
{{json}}
<script><br> app.factory("ff", function() {<br> return {<br> "noting" : "json"<br> };<br> });<br> app.controller("factory", function($scope, ff) {<br> $scope.json = ff;<br> });<br> </script>
angular的指令;
app.directive("heh", function() {
return {
restrict: "AE",
Replace : true,
transclude : true,
template : '
};
})
Using the .ng-switch directive (this is very similar to the template, it is our common angular method of clicking to hide and show the Tab plug-in)::
Copy code The code is as follows:
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
angular
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
ng-switch的使用
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
angular
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
angular对样式进行操作;(jQ是手动选择元素对元素样式进行操作,angular提供了一种更屌的方法,把元素的属性赋值给一个变量,你只要改变这个变量即可)
hehe--o(^▽^)o哇;
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
使用模板
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
updateangular的通知数据更新三种方式$scope.$digest(),$scope.$apply(),以及通过$scope.$watch监听进行更新;
{{hehe}}
the value set by $scope.$watch ==>> {{wat}}
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
angular中的工具方法列表
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
ng-switch的使用
- 1
- 2
- other
ng-src和ng-href;
复制代码 代码如下:
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
如何操作页面的样式,这个直接改绑定的数据模型就好了:
复制代码 代码如下:
angular对样式进行操作;(jQ是手动选择元素对元素样式进行操作,angular提供了一种更屌的方法,把元素的属性赋值给一个变量,你只要改变这个变量即可)
hehe--o(^▽^)o哇;
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
使用模板
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
updateangular的通知数据更新三种方式$scope.$digest(),$scope.$apply(),以及通过$scope.$watch监听进行更新;
{{hehe}}
the value set by $scope.$watch ==>> {{wat}}
http://cdn.bootcss.com/jquery/2.1.1/jquery.js">>
http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js">>
http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.css" rel="stylesheet">
angular中的工具方法列表