- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章AngularJS语法详解由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
模板和数据的基本运作流程如下:
用户请求应用起始页面 用户的浏览器向服务器发起一次http连接,然后加载index.html页面,这个页面包含了模板 angular被加载到页面中,等待页面加载完成,查找ng-app指令,用来定义模板的边界 angular遍历模板,查找指定和绑定关系,将触发一些列动作:注册监听器、执行一些DOM操作、从服务器获取初始化数据。最后,应用将会启动起来,并将模板转换成DOM视图 连接到服务器去加载需要展示给用户的其他数据 。
显示文本 。
一种使用{{}}形式,如{{greeting}} 第二种ng-bind="greeting" 。
使用第一种,未被渲染的页面可能会被用户看到,index页面建议使用第二种,其余的页面可以使用第一种 。
表单输入 。
。
。
在某些情况下,我们不想一有变化就立刻做出动作,而是要进行等待。例如:
。
。
非表单提交型的交互,以click为例 。
。
。
列表、表格以及其他迭代型元素 。
ng-repeat会通过$index返回当前引用的元素序号。 示例代码如下:
。
<html ng-app> <head> <title>表单</title> <script type="text/javascript" src="angular.min.js"></script> <script type="text/javascript"> var students = [{name:'Mary',score:10},{name:'Jerry',score:20},{name:'Jack',score:30}] function StudentListController($scope) { $scope.students = students,
。
} </script> </head> <body> <table ng-controller="StudentListController"> <tr ng-repeat='student in students'> <td>{{$index+1}}</td> <td>{{student.name}}</td> <td>{{student.score}}</td> </tr> </table> </body> </html> 。
。
隐藏与显示 ng-show和ng-hide功能是等价的,但是运行效果正好相反.
。
。
css类和样式 。
ng-class和ng-style都可以接受一个表达式,表达式执行的结果可能是如下取值之一:
表示css类名的字符串,以空格分隔 css类名数组 css类名到布尔值的映射 代码示例如下:
。
<html ng-app> <head> <style type="text/css"> .error { background-color: red; } .warning { background-color: yellow; } </style> <script type="text/javascript" src="angular.min.js"></script> <script> function HeaderController($scope) { $scope.isError = false; $scope.isWarning = false,
。
$scope.showError = function() { $scope.messageText = "Error!!!!" $scope.isError = true; $scope.isWarning = false; } 。
$scope.showWarning = function() { $scope.messageText = "Warning!!!" $scope.isWarning = true; $scope.isError = true; } } </script> </head> <body> <div ng-controller="HeaderController"> <div ng-class="{error:isError,warning:isWarning}">{{messageText}}</div> <button ng-click="showError()">Error</button> <button ng-click="showWarning()">Warning</button> </div> </body> </html> 。
。
css类名到布尔值的映射 示例代码如下:
。
<html ng-app> <head> <style type="text/css"> .selected { background-color: lightgreen; } </style> <script type="text/javascript" src="angular.min.js"></script> <script> function Restaurant($scope) { $scope.list = [{name:"The Handsome",cuisine:"BBQ"},{name:"Green",cuisine:"Salads"},{name:"House",cuisine:'Seafood'}],
。
$scope.selectRestaurant = function(row) { $scope.selectedRow = row; } } </script> </head> <body> <table ng-controller="Restaurant"> <tr ng-repeat='restaurant in list' ng-click='selectRestaurant($index)' ng-class='{selected: $index==selectedRow}'> //css类名到布尔值的映射,当模型属性selectedRow的值等于ng-repeat中得$index时,selectd样式就会被设置到那一行 <td>{{restaurant.name}}</td> <td>{{restaurant.cuisine}}</td> </tr> </table> </body> </html> 。
。
最后此篇关于AngularJS语法详解的文章就讲到这里了,如果你想了解更多关于AngularJS语法详解的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
在此处回答的另一个问题中,我发现了以下 JavaScript代码: function _dom_trackActiveElement(evt) { if (evt && evt.target)
if (A == 0) OR (B == 0) 怎么说? 最佳答案 只是为了讽刺: if (A === 0 || B === 0) 关于语法,我们在Stack Overflow上找到一个类似的问题:
var ret = [] ,xresult = document.evaluate(exp, rootEl, null, X
我一直在寻找一些类似于下例的 JavaScript。有人可以解释一下吗,因为我以前从未见过这样编写的 JavaScript。 “SomethingHere”和冒号代表什么?我习惯于看到函数 myFun
这是我的程序: delimiter // drop procedure if exists migContactToActor; create procedure migContactToActor(
我遇到了一个问题。我一直在使用 gcc 编译/汇编我的 C 代码一段时间,并且习惯了阅读 Intel 汇编语法。我在生成程序集文件时使用了 -masm=intel 标志。 但是最近因为公司迁移,拿到了
自上而下和自下而上语法有什么区别?举个例子就太好了。 最佳答案 首先,语法本身不是自上而下或自下而上的,解析器是(尽管有些语法可以被其中一个解析,但不能被另一个解析)。 从实践的角度来看,主要区别在于
我知道这是草率的代码,但它是: display dialog ("Start Screensaver. Please type: matrix, coffee, waffles, star, wate
这个问题已经有答案了: Giving name to a loop (6 个回答) 已关闭 8 年前。 我见过这个字符在 C# 中使用,就像 Java 中的扩展一样,但最近我在代码中发现了这个 loo
我正在尝试编写一个函数来检查字符串是否为回文,但我认为在使用字符串指针时存在一些错误。这段代码有什么问题? #include #include #define MAX 1000 int IsPalin
所以在this question我询问了一些 Javascript 是如何被压缩的。问题已得到解答,但以下片段让我非常困惑,以至于我不得不问另一个问题。在这里: for (Y = 0; $ = 'zx
假设我有一个接受这些参数的函数。 int create(Ptr * p,void * (*insert)(void *, void *)) { //return something later } 结
这个问题已经有答案了: Bitwise '&' operator (6 个回答) 已关闭 5 年前。 我在代码中找到了这个,但我从未遇到过像 & 这样的事情,仅 && if ((code & 1) =
我在处理继承类及其中的构造函数和方法的语法时遇到了问题。 我想实现一个类日期和一个子类 date_ISO,它们将按特定顺序设置给定的日、月、年,并通过一种方法将其写入字符串。我觉得我的基类日期工作正常
我正在尝试通过存储过程填充表,如下所示: SET @resultsCount = (SELECT COUNT(*) FROM tableA); SET @i = 0; WHILE @i THEN
谁能解释一下下面代码中的“<<”? mysql test<
刚刚开始学习 MySQL,这是一个菜鸟问题,也是我在 StackOverflow 上的第一个问题。 假设我有 12 个订单状态,我想从其中的 5 个中选择总计。我会使用: SELECT SUM(tot
我的编程背景是在学校学过一点Java。由于某些原因,JavaScript 语法往往让我感到困惑。下面的 JavaScript 代码是一种我不知道如何构成的语法模式: foo.ready = funct
我正在阅读 javascript 源代码,并且我以前没有编写过 javascript。我对它的一些语法感到困惑。 $(function () { window.onload=function
我什至不知道如何命名我想要的东西。那么让我举个例子来解释一下。 虽然火狐使用textContent,但其他浏览器支持innerText属性。顺便说一句,如果我使用了错误的术语,请纠正我。无论如何,到目
我是一名优秀的程序员,十分优秀!