开源一款好用的ajax和fetch拦截器
ajax interceptor, fetch interceptor
ajax interceptor, fetch interceptor
Mount linux file system under Macos: Laravel frequently used references: Laravel-mix webpack.mix.js example: package.json example (using Vue.js): Laravel blade template system interpolation V.S. Vue.js interpolation: Content distribution( in Vue.js) as…
It is better to use a service to handle Angular errors including errors outside your app(but sent back to app like backend error), network errors, internal errors and so on….
Observable is a stream of data/events to be observed/processed. Observer is as the name itself suggests, a consumer of the Observable stream. Subscription is a relationship between a Observable and…
This is the original source for your reference. https://hackernoon.com/everything-you-need-to-know-about-change-detection-in-angular-8006c51d206f Below it is the main change detection procedure: Angular has a bunch of high-level concepts to manipulate the views. I’ve written…
Adding globals.ts: 2. import global.ts to main.ts: 3. accessing modules from console: window[‘@angular/core’].ApplicationRef 4. use ng.probe() to check components and trigger actions.
https://hackernoon.com/here-is-how-to-get-viewcontainerref-before-viewchild-query-is-evaluated-f649e51315fb
1.Angular 2 支持的 View(视图) 类型有哪几种 ? Embedded Views – Template 模板元素 Host Views – Component 组件 1.1 如何创建 Embedded View 1.2 如何创建 Host View 2.Angular 2 Component 组件中定义的 <template> 模板元素为什么渲染后会被移除…
{ static: true } needs to be set when you want to access the ViewChild in ngOnInit. { static: false } can only be accessed in ngAfterViewInit. This is also what you want to go for…
所支持的选择器包括: 任何带有 @Component 或 @Directive 装饰器的类 字符串形式的模板引用变量(比如可以使用 @ViewChild(‘cmp’) 来查询 <my-component #cmp></my-component> 组件树中任何当前组件的子组件所定义的提供商(比如 @ViewChild(SomeService) someService: SomeService ) 任何通过字符串令牌定义的提供商(比如 @ViewChild(‘someToken’) someTokenVal: any ) TemplateRef(比如可以用 @ViewChild(TemplateRef) template; 来查询 <ng-template></ng-template>) @ViewChild(‘myname’, {read: ViewContainerRef}) target : ViewContainerRef; The following is an explanation to read: There can be several instances…
This is an example using ElementRef and Render2 to modify CSS style dynamically. import { Component, ElementRef, ViewChild, AfterViewInit, Renderer2 } from ‘@angular/core’; @Component({ selector: ‘my-app’, template: ` <h1>Welcome to…
use counter-reset and counter-increment. 2. HTML OL tag can also add numbers before <li></li> elements. But start attribute does not work normally. coffee milk tea coffee milk tea
File API: https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications File Reader: https://developer.mozilla.org/en-US/docs/Web/API/FileReader FormData: https://developer.mozilla.org/en-US/docs/Web/API/FormData Useage in Angular: https://www.cnblogs.com/zero-zm/p/9859171.html
请求拦截器 (Request Interceptor) 如果我们想要注册新的拦截器 (interceptor),我们需要实现 HttpInterceptor 接口,然后实现该接口中的 intercept 方法。 需要注意的是,请求对象和响应对象必须是不可修改的 (immutable)。因此,我们在返回请求对象前,我们需要克隆原始的请求对象。 next.handle(req) 方法使用新的请求对象,调用底层的 XHR 对象,并返回响应事件流。 响应拦截器 (Response Interceptor) 响应拦截器可以通过在 next.handle(req) 返回的流对象 (即 Observable 对象) 上应用附加的 Rx 操作符来转换响应事件流对象。 接下来要应用 JWTInterceptor 响应拦截器的最后一件事是注册该拦截器,即使用 HTTP_INTERCEPTORS 作为 token,注册 multi Provider: More examples: For Angular6+ and RXJS6+:
在 Angular 中有三种方式来生成单例服务: 把 @Injectable() 的 providedIn 属性声明为 root。 把该服务包含在 AppModule 或某个只会被 AppModule 导入的模块中。 1. 使用 providedIn 从 Angular 6.0 开始,创建单例服务的首选方式就是在那个服务类的 @Injectable 装饰器上把 providedIn 设置为 root。这会告诉 Angular 在应用的根上提供此服务。src/app/user.service.ts content_copyimport { Injectable } from ‘@angular/core’; @Injectable({ providedIn: ‘root’, }) export class UserService { } 2. NgModule…
Angular 中注入器是有层级结构的,即创建完注入器,我们可以基于它创建它的子注入器。 resolveAndCreate() – 根据设置的 provider 数组创建注入器 resolveAndCreateChild() – 调用已有注入器对象上的该方法,创建子注入器 当调用注入器 get() 方法,获取 token 对应的对象时,默认的查找方式是,优先从本级注入级获取,如果未找到,则往上一级查找,直到根级注入器。若未找到对应的依赖对象,默认会抛出异常。 使用示例 通过分析源码,我们也发现如果两个服务提供商 (Provider) 使用同一个 Token,却没有声明为 multiprovider,那么后面的会把前面的覆盖掉。此外需要注意的是,multiprovider 不能与普通的 provider 混用。 @Self()、@SkipSelf()、@Optional() 等装饰器有什么作用? @Self() – 表示只在本级注入器查找依赖对象 @SkipSelf() – 表示不从本级注入器获取依赖对象…
NgZone的简单使用 在Angular4中,如果模板中有一些变量在组件中经常变动,比如变量foo。 <div> 我经常变动: {{ foo }} </div> 在组件中它的初始值为0。 foo = 0; 假设在组件中有个循环,不断更新foo的值。 for (let i = 0; i < 100; i++) { setInterval(() => this.counter++, 10); } 那么频繁的变动将造成性能损耗。 Angular为我们提供了NgZone服务,对于一些频繁的操作,可以不去触发变更检测。…
Here comes a type alias definition in typescript: What does the type alias HandleError mean? What we usually see is type alias definitions with just one fat arrow like =>…
How it works Here’s how form validation works with Bootstrap: HTML form validation is applied via CSS’s two pseudo-classes, :invalid and :valid. It applies to <input>, <select>, and <textarea> elements. Bootstrap scopes the :invalid and :valid styles to parent .was-validated class, usually applied…
The JS code that relates to selectors of data-toggle is as below: Here data-toggle=”collapse” can be used with href or data-target. One the element with element.id, an initial class=”collapse” should…
Noticeably, Card component uses flex and CSS grid.
vertical-align: baseline; Check vertical-align in depth. @at-root a#{&} @at-root means the selector definition is valid outside of .badge at the root of CSS. a#{&} = a .badge. &:empty means .badge:empty…
See how flex relected layout directives are defined in Bootstrap4.
When requesting for Restful APIs of backend, somtimes OPTION request is sent prior to a POST request to inquire http method support abilities of the backend server. When if the…
I had a look at Bootstrap 4.2 SCSS source code and I can tell that it has been written quite clean and clear. Let’s quote spacing part( Margin and padding)…
When I was debugging a CI/CD open source project called piplin(http://piplin.com), I failed setting up a web socket connection between node.js server and the browser. The browser is using cocket.io-client…
STEPS TO ADD WORDPRESS SOCIAL-SHARE WIDGET