简体   繁体   English

AngularJS:严格模式之外尚不支持块范围的声明(let,const,函数,类)

[英]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.

相关问题 Typescript和Uncaught SyntaxError:在严格模式之外尚不支持块范围的声明(let,const,function,class) - Typescript and Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode 在Kriasoft React样板中,严格作用域之外的严格作用域尚不支持const函数类的块范围声明 - Block-scoped declaration let const function class not yet supported outside strict mode in kriasoft react boiler plate Angular:在Chrome中严格模式之外尚不支持块范围声明 - Angular: Block-scoped declarations not yet supported outside strict mode in Chrome InAppBroswer:未捕获的SyntaxError:在Android App上加载js时,尚不支持块范围的声明.. 外部严格模式 - InAppBroswer: Uncaught SyntaxError: Block-scoped declarations .. not yet supported when loading js on Android App. outside strict mode 为什么在 JavaScript 中为块范围变量声明选择名称“let”? - Why was the name 'let' chosen for block-scoped variable declarations in JavaScript? Visual Studio代码,块范围的声明 - Visual Studio Code, Block-scoped declarations (教程)脚本由于SyntaxError无法运行:范围限定的声明 - (Tutorial) Script does not run due SyntaxError: Block-scoped declarations 在类实例中获取块范围变量 - get block-scoped variable in class instance 块范围的声明…TypeScript和Asp.net MVC 5 - Block-scoped declarations … TypeScript and Asp.net MVC 5 如何修复nodemon“块范围声明...”错误? - How to fix nodemon "block-scoped declarations..." error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM