且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Angular 中使用方括号的目的是什么?

更新时间:2022-06-12 04:31:37

它可以缩小 AngularJS 代码.AngularJS 使用参数名称将值注入您的控制器函数.在 JavaScript 缩小过程中,这些参数被重命名为较短的字符串.通过使用字符串数组告诉函数注入了哪些参数,AngularJS 仍然可以在重命名参数时注入正确的值.

It enables AngularJS code to be minified. AngularJS uses parameter names to inject the values to your controller function. In JavaScript minification process, these parameters are renamed to shorter strings. By telling which parameters are injected to the function with a string array, AngularJS can still inject the right values when the parameters are renamed.