In a previous lesson we learned about implementing a custom preloading strategy. That gives you a lot of control over which route to preload and which not, whether it is based on the user's permissions or some runtime app config. In this lesson we're…
By default the response body doesn’t contain all the data that might be needed in your app. Your server might return some special header which you have to read explicitly. In such case we can use the { observe: ‘response’} configuration of the Angula…
TL;DR 脏检查是一种模型到视图的数据映射机制,由 $apply 或 $digest 触发. 脏检查的范围是整个页面,不受区域或组件划分影响 使用尽量简单的绑定表达式提升脏检查执行速度 尽量减少页面上绑定表达式的个数(单次绑定和ng-if) 给 ng-repeat 添加 track by 让 angular 复用已有元素 什么是脏数据检查(Dirty checking) Angular 是一个 MVVM 前端框架,提供了双向数据绑定.所谓双向数据绑定(Two-way data binding)…
angular路由 使用案例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>test</title> </head> <body ng-app="myApp"> <a href="" ui-sref="lol"&g…
User input validation is a core part of creating proper HTML forms. Form validators not only help you to get better quality data but they also guide the user through your form. Angular comes with a series of built-in validators such as required or ma…
updatePassenger(passenger: Passenger): Observable<Passenger> { let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); return this.http .put(`${PASSENGER_API}/${passenger.id}`, passe…
Creating custom validators is easy, just create a class inject AbstractControl. Here is the form we want to validate it: form = this.fb.group({ store: this.fb.group({ branch: ['', [Validators.required, StockValidators.checkBranch]], code: ['', Valida…
Create a custom validtor which only accepts the string start with '123'; function skuValidator(control){ if(!control.value.match(/^123/)){ return {invalidSku: true}; } } If it not start with 123, then return the object {invalidSku: true}, which later…
Prevent Partail Page display: By using Resolver: @Injectable() export class MovieResolver implements Resolve<IMovie> { constructor(private movieService: MovieService) { } resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable…