[英]AngularJS: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
So I had this directive: 所以我有了这个指令:
app.directive('customDropdown', function() {
return {
restrict: 'E',
templateUrl: '/static/templates/directive_templates/customdropdown.html',
link: function(scope, element, attrs) {
console.log(attrs.custom-class);
}
}
})
Markup: 标记:
<custom-dropdown custom-class="custom-select-menu">
</custom-dropdown>
But, due to console.log(attrs.custom-class)
I get the error mentioned in the question. 但是,由于
console.log(attrs.custom-class)
我得到了问题中提到的错误。 It goes away when I change custom-class
to just custom
. 它消失时,我改变
custom-class
,只是custom
。 Any idea why the error was popping up? 知道为什么会弹出错误吗? Can't use hyphens?
不能使用连字符?
attrs.custom-class
custom-class is not a valid identifier in javascript. attrs.custom-class
自定义类在javascript中不是有效的标识符。 So you have 2 choices : 因此,您有2个选择:
Rename custom-class into something else without an hypen. 将自定义类重命名为没有连字符的其他名称。
Use the bracket syntax : attrs['custom-class']
使用方括号语法:
attrs['custom-class']
This means that you must declare strict mode by writing "use strict" at the beginning of the file or the function to use block-scope declarations. 这意味着您必须通过在文件或使用块作用域声明的函数的开头编写“ use strict”来声明严格模式。
function test(){
"use strict";
let a = 1;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.