ngc
- Angular compilerngcc
- Angular compatible compiler- .
fems
- Flattened ES Module, this is the angular file format for ES Module. - AOT - Ahead of Time Compilation
- JIT - Just in Time Compilation
ng add
vsnpm install
-ng add
is a schematic that can install packages and run additional code to set up the package.npm install
is just installing the package.- Angular HttpClient底层是基于HttpXMLRequest和Jsonp的,所以可以使用
XMLHttpRequest
的所有方法。 - HostBinding - Angular Decorator that declares a DOM property to bind to. is equivalent to [property]=”expression”.
- Angular如何处理scss文件的?package.json中并没有安装sass对应的包。难道是Angular CLI内置了sass的编译器,所以不需要安装sass包?
- :ng-deep和:host如何配合使用
- Angular中的ViewEncapsulation是如何实现的?有哪三种封装模式?
- Reload page on same url with different parameters
1
2
3
4
5
6
7
8export const appConfig: ApplicationConfig = {
providers: [
provideRouter(
appRoutes,
withRouterConfig({ onSameUrlNavigation: 'reload' })
),
],
}; - 如何使用Native Federation?
- How to mock service in Unit test(Jest) in Angular? https://stackoverflow.com/questions/79071748/mock-provided-service-in-standalone-component-in-jest-unit-test
- 这种怎么测试?添加到Jest异步测试中。
1
2
3
4
5getData() {
this.dataService.fetchData().subscribe((data: any) => {
this.products = data;
});
} - Generate module based component after Angular 17.
Start from Angular 17, Angular CLI use standalone component by default, however, you can still generate module based application with the following command.
1 | ng g app my-app --standalone=false |
- Why Angular use
Decorator
instead ofAbstract Class
forComponent
andService
? - Android No matching client found for package name ‘com.jiyuzhai.caoquanbei’, update package name in file app/src/google-services.json to match your application id.
- 一个Angular文件内可以定义多个组件。
- Event loop and browser rendering是如何交互的,也就是Browser rendering是在Event loop哪个阶段进行的?
- NW.js和Electron类似,都是用来开发跨平台桌面应用的框架。
- Traceur和Babel都是用来将ES6+代码转换为ES5代码的工具。Traceur是Google开发的,Babel是社区开发的。
- RxJS 社区中常见的约定:以 $ 结尾的变量通常表示它是一个 Observable(可观察对象)。
- Virtual Dom的好处是什么?为什么要使用Virtual Dom?
- performance - 批量更新dom,而不是每次更新都操作dom。
- 可以跨平台 - 这点很重要,多数人回到虚拟DOM,都说性能,但是跨平台也很重要,虚拟DOM相当于一个中间层,可以对接不同平台,比如Android,IOS,Desktop,Web等。
- 为什么有些框架不用虚拟DOM还更快?这是因为React/Vue等框架的最小单元就是组件,无法做到控件级别的更新,所以只能更新整个组件,这样就会有性能问题。而有些框架是以控件为最小单元,所以可以做到控件级别的更新,这样就会更快。
- Angular router可以传参数,用navigationExtras对象中的state.
- 在导航时传递参数
1
this.router.navigate(['/detail'], { state: { id: 1 } });
- 在接收参数的组件中获取参数
1
const id = history.state.id; // 不对吧?history 哪来的?
- GraphQL playground.
- You should never use function in angular template. - url
- Directive composition API - search on angular.dev, this is a new feature in angular 15, why this is useful?
- javascript, generator functions
default
import syntax in ES6.WeakMap
is not iterable, why?TypedArray
is not array.- Angular
BehaviorSubject
vsSubject
-BehaviorSubject
needs an initial value,Subject
does not. - Angular
aot
can be enabled/disabled inangular.json
file. it.each
inJest
- This need real example from project.- Why Jest need transformer? Because Jest only understand JavaScript, so it needs transformer to transform other file types to JavaScript. for example ts -> js, tsx/jsx -> js vue/angular -> js, by default Jest use babel-jest as transformer, you can also use angular-jest-preset for Angular project.
- Proxy.revocable(target, handler).
- What is cross-site request forgery (CSRF) attack? How to prevent it?
- Website defacement - what’s this?
- steps to use web component.
- Grid layout.
HTML
page will always show even it contains errors, the console won’t display html error, it only show javascript errors.- Html中标签的样式按照LVHA的顺序来写,这样可以避免样式覆盖的问题。
:link
- 未访问的链接:visited
- 已访问的链接:hover
- 鼠标悬停:active
- 激活状态
- css function
env
-env()
函数可以用来获取环境变量的值,比如获取视口的宽度。 - css
@support
operator -@supports
操作符用来检测浏览器是否支持某个CSS属性。 - video tag:
source
vssrc
- What’s the differences? - CSS attributes selectors -
^
,$
,*
,~
- What’s the differences? [attr*=value] vs [attr~=value]. - compare in javascript:
- ==
- ===
- Object.is
- SameValueZero - MDN
- chunk load error: https://rollbar.com/blog/javascript-chunk-load-error/
- drag and drop:
- What’s the differences between
markForCheck()
anddetectChanges()
in Angular? - stackoverflow - SASS vs SCSS
- SASS - Syntactically Awesome Style Sheets
- SCSS - Sassy CSS
- SASS is the older syntax, it use indentation to define blocks, SCSS is the newer syntax, it use curl braces to define
- 如何查看JS编译后的代码?比如变量提升后的代码,Google的V8引擎可以实现这个功能。而Node底层也是V8,所以用Node命令可以查看,但是输出的代码不是很直观。需要进一步研究,参考资料:https://medium.com/@drag13dev/https-medium-com-drag13dev-how-to-get-javascript-bytecode-from-nodejs-7bd396805d30
- JavaScript中有些时候使用new和不使用new结果完全不同,比如:
- Date() vs new Date(): Date()返回的是字符串,new Date()返回的是Date对象。
- String() vs new String(): String()返回的是字符串,new String()返回的是String对象。- 在这里, 不加new其实相当于类型转换
- Number() vs new Number(): Number()返回的是数字,new Number()返回的是Number对象。- 同上
- 注意:对于Array,加不加new,结果一样,都是数组。
Harmony Import/Export
- 其实就是ES6中的Import/Export,这是ES6的模块化规范,可以用来导入导出模块。参考这里:https://en.wikipedia.org/wiki/ECMAScript_version_history#4th_Edition_(abandoned) 和这里:https://stackoverflow.com/questions/52871611/what-is-harmony-and-what-are-harmony-exports- Immutable.js - 一个用来处理不可变数据的库,可以用来提高性能。参考这里:https://immutable-js.com/
- 性能优化好文 - https://zhuanlan.zhihu.com/p/41292532
- html中的checkbox/radio button默认的样式由浏览器决定,不是十分好定制化,如果只是更改颜色的话,可以使用accent-color属性,如果要更改大小的话,可能就需要其他手段了。比如这里:https://stackoverflow.com/questions/4148499/how-to-style-a-checkbox-using-css/69164710#69164710
- 有哪些样式是CSS改变不了的?
- select控件中option的高亮色,就是鼠标划过每个选项时的高亮色,这个一般是蓝色,且不能更改。如果想改,那么需要使用ul/li模拟select控件。
- 浏览器如何处理双击,双击的时候,浏览器会选取最近的能选到的文本,所以随便打开一个网站,找个空白处双击一下,你会发现有文本被选中了。如何禁止这种行为呢?
以下方法会禁止所有选中文本的行为,包括用户主动选择的,要找到最近的node,手动设置一下。
1 | function disableTextSelection() { |