AngularJS学习笔记之基本指令(init、repeat)
网络编程 2021-07-04 21:48www.168986.cn编程入门
AngularJS 指令是扩展的 HTML 属性,带有前缀 ng-。ng-app 指令初始化一个 AngularJS 应用程序。ng-init 指令初始化应用程序数据。ng-model 指令把应用程序数据绑定到 HTML 元素。
AngularJS学习笔记之基本指令(init、repeat)
<h3>ng-init初始化变量</h3> <div ng-init="name='aurora';age='18'"> <p ng-bind="name+','+age"></p> <p>{{name+','+age}}</p> <p ng-bind="name"></p> <p ng-bind="age"></p> </div> <h3>ng-init初始化对象</h3> <div ng-init="hero={name:'aurora',role:'sup',line:'不管刮风还是下雨,太阳照常升起'}"> <p ng-bind="hero.name+','+hero.role+','+hero.line"></p> <p ng-bind="hero.name"></p> <p ng-bind="hero.role"></p> <p ng-bind="hero.line"></p> </div> <h3>ng-init初始化数组</h3> <div ng-init="heros=['曙光女神','堕落天使','魂锁典狱长']"> <p ng-bind="heros[0]+','+heros[1]+','+heros[2]"></p> <p ng-bind="heros[0]"></p> <p ng-bind="heros[1]"></p> <p ng-bind="heros[2]"></p> </div> <h3>ng-controller控制器</h3> <div ng-controller="contr-2"> First Name: <input type="text" ng-model="firstName"> Last Name: <input type="text" ng-model="lastName"> Full Name : <span>{{firstName + "," + lastName}}</span> Full Name : <span ng-bind="firstName + ',' + lastName"></span> </div> <h3>ng-repeat遍历无重复集合</h3> <div ng-init="names=[1,2,3]"> <ul> <li ng-repeat="x in names"> {{x}} </li> </ul> </div> <h3>ng-repeat遍历重复集合</h3> <div ng-init="number=[1,2,2,3]"> <ul> <li ng-repeat="x in number track by $index"> {{x}} </li> </ul> </div> <h3>ng-repeat遍历对象</h3> <div ng-controller="contr-3"> <ul> <li ng-repeat="(key,value) in object track by $index"> {{key+":"+value}} </li> </ul> </div> <h3>ng-repeat遍历对象(按原有顺序)</h3> <div ng-controller="contr-4"> <ul ng-repeat="obj in objs "> <li ng-repeat="(key,value) in obj "> {{key+":"+value}} </li> </ul> </div> <h3>ng-repeat遍历对象(属性详解)</h3> <table ng-controller="contr-5"> <tr ng-repeat="(key, value) in objs "> <td>学号: <span ng-bind="$index"></span> </td> <td> <span ng-bind="key"></span>: <span ng-bind="value"></span> </td> <td>是否为奇数? <span ng-bind="$odd"></span> </td> <td>是否为偶数? <span ng-bind="$even"></span> </td> <td>排行是老大? <span ng-bind="$first"></span> </td> <td>排行最小? <span ng-bind="$last"></span> </td> <td>排行中间? <span ng-bind="$middle"></span> </td> </tr> </table> <h3>ng-repeat start/end</h3> <div ng-controller="contr-6"> <div ng-repeat-start="(key,value) in objs"> <p>学号: <span ng-bind="$index"></span> </p> <p> <span ng-bind="key"></span>: <span ng-bind="value"></span> </p> </div> <div ng-repeat-end></div> </div>
以上所述上就是本文的全部内容了,希望大家能够喜欢。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程