AngularJs 初级入门 学习笔记

it2022-06-29  75

刚学angular, 做一些笔记方便自己翻看.

ng-app: 填写模块的名称

ng-init: 初始化数据(一般通过控制器初始化)

ng-model: 填写数据模型

ng-bind: 绑定数据模型, 用于展示数据

ng-controller: 控制器, 用于存储数据,改变数据等

ng-disabled: 绑定应用程序数据到 HTML 的 disabled 属性

ng-show(ng-hide): 通过数据的true或false来控制 DOM 元素显示或隐藏

ng-事件名: 绑定HTML的对应事件(例如: ng-click 绑定onclick事件) 注:onchange事件不可以绑定

ng-include: 用来包含HTML内容,需要在服务器环境下

ng-repeat: 用来遍历数据并且填在HTML中

{{ $scope.name }}: 两个大括号是Angular的表达式,它们可以包含文字、运算符和变量

$http.get(url)  用于读取服务器数据的函数

例:

1 function customersController($scope,$http) { 2   $http.get("../xxx.php") 3   .success(function(response) {$scope.data = response;}); 4

 

创建模块

 1 var app = angular.module("myApp",[]); //myApp为模块名 

 

新建控制器

1 app.controller("myController",function($scope){ 2   $scope.data = "something"; 3   $scope.method = function(){ 4     /* 一些操作 */ 5   } 6 })

 

过滤器

用管道符"|"接在后面即可,例如

1 <p><input type="text" ng-model="name"></p> 2 <ul> 3   <li ng-repeat="x in names | filter:name | orderBy:'country'"> 4     {{ (x.name | uppercase) + ', ' + x.country }} 5   </li> 6 </ul>

currency: 格式化数字为货币格式filter: 从数组项中选择一个子集lowercase: 格式化字符串为小写orderBy: 根据某个表达式排列数组uppercase: 格式化字符串为大写

 

转载于:https://www.cnblogs.com/kyles/p/4724371.html

相关资源:数据结构—成绩单生成器

最新回复(0)