For example we have those code: <div class="course-category" [ngSwitch]="course.category"> <div class="category" *ngSwitchCase="'BEGINNER'">Beginner</div> <div class="category" *ngSwit…
// Component: this.coursesTotal = this.course,length <div i18n>{coursesTotal, plural, =0 {No course in available.} =1 {One course is available.} other {A total of {{coursesTotal}} courses are available.} } </div>…
To add translation to the application: <button (click)="onEditCourse()" i18n>Edit button</button> 'i18n' is for Angular CLI to extract all the string which need to be translated. Run: ng xi18n It will generate messages.xif, this file…
You can use Select and Option elements in combination with ng-for and ng-model to create mini-forms that change your data as you make a selection. /** * Created by wanzhen on 23.10.2015. */ import {Component, View, NgFor, FORM_DIRECTIVES} from 'angul…
angular.Module Angular模块配置接口. 方法: provider(name,providerType); name:服务名称. providerType:创建一个服务的实例的构造函数. factory(name,providerFunction); name:服务名称. providerFunction:创建服务的实例的函数. service(name,constructor); name:服务名称. constructor:一个将被实例化的构造函数. value(name,…
angular.injector 创建一个injector对象, 调用injector对象的方法可用于获取服务以及依赖注入. 格式:angular.injector(modules); modules:  Array 注入的模块(一个或多个). 使用代码: (function () { angular.module("firstModule", []) .service("firstService", function () { this._log = functi…
angular.isArray 判断括号内的值是否为数组. 格式:angular.isArray(value); value: 被判断是否为数组的值. --------------------------------------------------------------- angular.isDate 判断括号内的值是否是一个时间. 格式:angular.isDate(value); value:被判断是否为时间的值. -----------------------------------…
angular.uppercase 将指定的字符串转换成大写 格式:angular.uppercase(string); string:被转换成大写的字符串. 使用代码: var str = "ABCabc"; var upperCase = angular.uppercase(str);//ABCABC angular.lowercase 将指定的字符串转换成小写 格式:angular.lowercase(string); string:被转换成小写的字符串. 使用代码: var s…
angular.bind 返回一个调用self的函数fn(self代表fn里的this).可以给fn提供参数args(*).这个功能也被称为局部操作,以区别功能. 格式:angular.bind(self,fn,args); self:object  对象: fn的上下文对象,在fn中可以用this调用 fn:function: 绑定的方法 args:传入fn的参数 使用代码: var obj = { name: "Any" }; var fn = function (Adj) { c…
angular.element 将DOM元素或者HTML字符串一包装成一个jQuery元素. 格式:angular.element(element); element:包装成jquery对象的html字符串或者dom元素 jqLite提供的方法: addClass() after() append() attr() bind() – 不支持命名空间,选择器和事件数据 children() – 不支持选择器 clone() contents() css() data() empty() eq()…
angular.equals 对比两个对象/值是否相等.支持值类型.正则表达式.数组和对象. 如果下列至少有一个是正确的,则将两个对象/值视为相等. 两个对象/值能通过===比较. 两个对象/值是同一类型/他们的属性一致并且通过angular.equals详细比较. 两者都是NaN. (在javascript中, NaN == NaN => false. 但是我们认为两个 NaN 是平等的) 两个值都代表相同的正则表达式 (在JavaScript里, /abc/ == /abc/ => fal…
angular.identity 函数返回本身的第一个参数.这个函数一般用于函数风格. 格式:angular.identity() 使用代码: (function () { angular.module("Demo", []) .controller("testCtrl", testCtrl); function testCtrl() { var getResult = function (fn, val) { return (fn || angular.ident…
angular.forEach 调用迭代器函数取每一项目标的集合,它可以是一个对象或数组.迭代器函数与迭代器(value.key)一起调用,其中值是一个对象属性或数组元素的值,而数组元素是对象属性的关键或数组元素索引.为函数指定一个可选的上下文. 格式:angular.forEach(obj,iterator,[context]); obj:遍历的对象 iterator:迭代器 [content]: 对象为迭代器函数的上下文(this) 使用代码: var arr = [{ name: "A&q…
Make sure install the latest Angular v6 with Angular CLI. Checkout ght Github for the code. 1. Create a new application: ng new elementApp 2. Install @angular/elements package: ng add @angular/elements --project-name=<your_project_name> 3. Generate…
Each component has its own ChangeDetectorRef, and we can inject ChangeDetectorRef into constructor: export class ChildComponent implements OnInit { constructor( private cdr: ChangeDetectorRef ) For example if you have a huge list can be updated in re…
When we pass value to a component, normally we use @Input. <my-comp [courses]="(courses$ | async) as courses" ></my-comp> @Component({...}) export class MyComp implements OnInit { @Input() courses; ... } Angular will check whether an…
1. Installl latest @angular/cli: sudo npm i -g @angular/cli@next The version I used is:6.0.0-rc.10 2. Create a new application: ng new cdk-demo --routing 3. Install material and cdk packages: Here need to add @next, because by the time I tried the ap…
If we want to add global event handler, we can use 'EventManager' from '@angular/platform-broswer'. Now we have a modal component, we want to click 'Esc' key to close the modal. <au-modal class="auth-modal" *auModalOpenOnClick="[loginBut…
Previously we have tab-panel template defined like this: <ul class="tab-panel-buttons" *ngIf="tabs"> <li [ngClass]="{selected: tab.selected}" (click)="selectTab(tab)" *ngFor="let tab of tabs;">…
Create an app with routing config: ng new mynewapp --routing If you want to generate a new module with routing , you can also do: ng g m mynewModule --routing Define env variable: You can create a custom env file inside env folder. // environment.ch.…
When want to display different component based on some conditions: <div class='course-category' [ngSwitch]="course.category"> <div class="category" *ngSwitchCase="'BEGINNER'">Beginner</div> <div class=&qu…
相信不少同学模拟过腾讯的QQ做一个聊天应用,至少我是其中一个. 过程中我遇到的一个问题就是QQ输入框,自适应高度,最高高度为3row. 如果你也像我一样打算使用textarea,那么很抱歉,你一开始就错了. textarea不是不可以的,然后我是这样错的.(就是监听scroll 如果出现了,就增加1rows 的高度)然而这样真的很挫 textarea.bind('change','keydown'){ if(scrollTop > 0 ) { textarea.rows += 1 } } 正确的…
上一节我们走通了基本的SPA基础结构,这一节会更彻底的将后端的视图.路由.控制器全部移到前端.篇幅比较长,主要分页面改造.使用AngularUI两大部分以及一些优化路由.使用Angular的其他指令的学习.篇幅虽然长,但熟悉了就是这个套路,特别是第一部分.重点是理解Angular这种操作数据而不是操作Dom的编程方式. 一.移除服务端依赖 上一节中我们还保留了基于jade的layout.为此还保留一个Express的控制器.这一节我们全部在客户端(app_client)实现.先在app_clie…
angular结合easyui这事其实并不是很合适,因为:angular的特点之一是双向绑定,页面元素与页面逻辑之间解耦:easyui是对页面元素进行封装,甚至一些组件是隐藏了原本的dom元素,初始化时创建新的元素来实现功能的.在某种程度上来说,angular和easyui在工作原理上是冲突的,当然,下面就是但是了,不然就不太好往下写了. 但是,easyui的验证控件validatebox的验证控件提示明显,UI效果比较友好,而且不会影响angular的正常工作,所以我对用这两个结合做验证非常喜…
目录: $rootScope,ng-app,.run(),ng-include,ng-repeat,ng-if,ng-switch,ng-init ng-show/ng-hide,ng-model,ng-bind-template,ng-change,ng-submit,ng-cloak,ng-bind 详细介绍: $rootScope 是作用域链的起始点,任何嵌套在ng-app内的指令都会继承$rootScope ng-app 任何具有ng-app属性的dom元素都将被标记为$rootScop…
在angular中,$scope是一个关键的服务,可以被注入到controller中,注入其他服务却只能是$rootscope.scope是一个概念,是一个类,而$rootscope和被注入到controller中的一个具体的$scope都是一个个具体的对象.$rootscope之所以被称为"root"的原因就是他是所有scope的祖先,$rootscope是在angular启动流程中建立的(上上期讲过),而被注入到controller中的$scope则是在视图创建的时候通过父辈的$s…
angular的表单,点击确定进行创建,支持批量创建,表单验证有样式提醒; <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> </head> <link rel="stylesheet" href="./../node_modules/bootstrap/dist/css/bootstrap.cs…
一.布尔属性指令: ng-disabled:就是ng-disabled=true-->就指向不可用 <!doctype html> <html ng-app=""> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular.js"></script> </head> <…
1.引导程序 使用ng-app开始引导一个程序:标记了AngularJS应用的作用域 <!doctype html> <html lang="en" ng-app> 双括号绑定表达式: <p>Nothing here {{'yet' + '!'}}</p> 2.视图和模板 其核心为MVC模式 原理:在AngularJS中,一个视图是模型通过HTML模板渲染之后的映射 HTML模板: 包含ng-controller指令,和ng-repeat…
刚学没多久,作了一个小项目APP,微信企业号开发与微信服务号的开发,使用的是AngularJS开发,目前项目1.0版本已经完结,但是项目纯粹为了赶工,并没有发挥AngularJS的最大作用,这几天项目到了测试那边,自己正好闲下来了,可以把项目优化一下,目标是做成SPA(单页面应该程序),因为Android版本实在是卡得不行,iPhone上面运行还可以见得了人.不得不优化,SPA做完了,还要做本地化存储.OK,把今天的笔记写下来,回家再完善 ##ListController.js /// <ref…