AngularJS:块作用域声明(let、const、function、class)在严格模式之外还不支持
AngularJS: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
我有了这个指令:
app.directive('customDropdown', function() {
return {
restrict: 'E',
templateUrl: '/static/templates/directive_templates/customdropdown.html',
link: function(scope, element, attrs) {
console.log(attrs.custom-class);
}
}
})
标记:
<custom-dropdown custom-class="custom-select-menu">
</custom-dropdown>
但是,由于console.log(attrs.custom-class)
,我得到了问题中提到的错误。当我把custom-class
变成custom
时它就消失了。知道为什么会弹出错误吗?不能使用连字符?
attrs.custom-class
custom-class在javascript中不是有效的标识符。所以你有两个选择:
-
将custom-class重命名为不带连字符的名称
-
使用括号语法:
attrs['custom-class']
这意味着你必须通过在文件或函数的开头写"use strict"来声明严格模式,以使用块作用域声明。
function test(){
"use strict";
let a = 1;
}
相关文章:
- 任何浏览器都不支持javascript函数
- 对象不支持属性或方法“自动完成”
- 对象没有'不支持set_viewXML
- 您的平台不支持RxJS-Array.observe
- 错误:语法错误,无法识别的表达式:不支持的伪:无效/RectJS/Unit Testing
- 使用Facebook登录,但仍然可以获得:“;此标识池不支持未经身份验证的访问“;
- 415(不支持的媒体类型)错误
- 字符串替换-不支持格式字符'}'
- CSS3卡翻转动画,检测是否不支持
- IE中不支持JQuery window.location.hash
- javascript表单字段submit:Object dos'在IE8中不支持此属性或方法
- 对象不支持对象IE 8
- 不支持Three.js FBX二进制格式
- 使用gmail-api发送电子邮件错误:此api不支持解析表单编码的输入
- 如何在不支持HTML字符的邮件正文中发送%签名
- [$se:iequicks]严格上下文转义不支持Internet Explorer版本<9在怪癖模式
- AngularJS:块作用域声明(let、const、function、class)在严格模式之外还不支持
- 未捕获的SyntaxError:在严格模式之外还不支持块范围的声明(let、const、function、class)
- 使用IE9兼容模式时,Javascript可以在IE8中工作,但不支持安装IE8
- Hogan不支持预编译模式下的lambda