大佬教程收集整理的这篇文章主要介绍了AngularJS 最常用的八种功能,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
转自:http://zhaoyanblog.com/archives/99.html
ng-repeat让table ul ol等标签和js里的数组完美结合
<ul>
<li ng-repeat="person in persons">
{{person.namE}} is {{person.agE}} years old.
</li>
</ul>
你甚至可以指定输出的顺序:
<li ng-repeat="person in persons | orderBy:'name'">
任何有用户输入,只要是有值的html标签,都可以动态绑定js中的变量,而且是动态绑定。
<input type="text" ng-model='password'>
对于绑定的变量,你可以使用{{}} 直接引用
<span>you input password is {{passworD}}</span>
如果你熟悉fiter,你可以很容易的按你的需要格式输出
<span>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span>
使用Ng-click你可以很容易的为一个标签绑定点击事件。
<button ng-click="pressMe()"/>
当然前提是你要在$scope域中定义的自己的pressMe方法。
和传统的onclick方法不同,你甚至可以为ng-click方法传递一个对象,就像这样:
<ul>
<li ng-repeat="person in persons">
<button ng-click="printf(person)"/>
</li>
</ul>
分支语句让你在界面上都可以写逻辑判断。
<ul>
<li ng-repeat="person in persons">
<span ng-switch on="person.sex">
<span ng-switch-when="1">you are a boy</span>
<span ng-switch-when="2">you are a girl</span>
</span>
<span ng-if="person.sex==1">you may be a father</span>
<span ng-show="person.sex==2">you may be a mother</span>
<span>
please input your baby's name:<input type="text" ng-disabled="!person.hasBaby"/>
</span>
<span>
</li>
</ul>
表单中的输入框,你可以使用上面的标签来实现对用户输入的校验。
从字面意思上你已经知道了它们的意思。
<form name="yourForm">
<input type="text" name="inputText" required ng-trim="true" ng-model="userNum" ng-pattern="/^[0-9]*[1-9][0-9]*$/" ng-maxlength="6" maxlength="6"/>
</form>
你可以通过
你可以通过
你通过$scope.userNum获得的输入内容是去掉前后空白的,因为ng-trim的存在。
<SELEct ng-model="yourSELEcted" ng-options="person.id as person.name in persons"></SELEct>
下拉框中@L_696_25@的是person.name,当你选中其中一个的时候,你可以通过yourSELEcted得到你选中的person.id.
ng-style帮你轻松控制你的css属性
<span ng-style="myColor">your color</span>
你可以通过给myColor赋值的形式来改变你想要的效果,就像这样:
$scope.myColor={Color:'blue'};
$scope.myColor={cursor: 'pointer',color:'blue'};
AngularJS 提供了一个类似jquery的
$http({method : 'POST',params : { id:123},data:{name:'john',age:27},url : "/mypath"})
.success(function(response,status,headers,config){
//do anything what you want;
})
.error(function(response,config){
//do anything what you want;
});
如果你是POST请求,params里的数据会帮你拼到url后面,data里的数据会放到请求体中。
以上是大佬教程为你收集整理的AngularJS 最常用的八种功能全部内容,希望文章能够帮你解决AngularJS 最常用的八种功能所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。