ctorParameters.map不是angular2-mdl中的函数

前端之家收集整理的这篇文章主要介绍了ctorParameters.map不是angular2-mdl中的函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用angular2-mdl与angular-cli.我在app.module.ts中导入了MdlModule.

当我尝试使用< mdl-textfield type =“text”label =“Text ...”float-label>< / mdl-textfield>时,会产生错误

ctorParameters.map is not a function in angular2-mdl

我不知道我应该做什么

这是我的角度cli.json.

"dependencies": {
    "@angular/common": "~2.0.0","@angular/compiler": "~2.0.0","@angular/core": "~2.0.0","@angular/forms": "~2.0.0","@angular/http": "~2.0.0","@angular/material": "^2.0.0-alpha.9-3","@angular/platform-browser": "~2.0.0","@angular/platform-browser-dynamic": "~2.0.0","@angular/router": "~3.0.0","@types/moment-timezone": "^0.2.33","angular-cli": "^1.0.0-beta.17","angular2-jwt": "^0.1.25","angular2-mdl": "^2.9.0","bootstrap": "^3.3.7","bourbon": "^4.2.7","core-js": "^2.4.1","font-awesome": "^4.7.0","hammerjs": "^2.0.8","moment": "^2.17.1","moment-timezone": "^0.5.10","node-sass": "^3.13.0","primeng": "^1.1.0","rxjs": "5.0.0-beta.12","ts-helpers": "^1.1.1","zone.js": "^0.6.23"
  },"devDependencies": {
    "@types/jasmine": "^2.2.30","@types/moment": "^2.13.0","@types/node": "^6.0.42","angular-cli": "1.0.0-beta.17","bootstrap-sass": "^3.3.7","codelyzer": "~0.0.26","jasmine-core": "2.4.1","jasmine-spec-reporter": "2.5.0","karma": "1.2.0","karma-chrome-launcher": "^2.0.0","karma-cli": "^1.0.1","karma-jasmine": "^1.0.2","karma-remap-istanbul": "^0.2.1","protractor": "4.0.9","ts-node": "1.2.1","tslint": "3.13.0","typescript": "2.0.2"
  }
看来这个问题需要一些澄清:

为什么我们看到这个错误消息?

如果angular2的组件库要与AOT兼容,则需要使用ngc(@ angular / compiler-cli)进行编译.这将为每个组件生成* .Metadata.json文件.此外,这会为包含有关构造函数参数的信息的每个组件生成js文件.如果软件包是使用@ angular / compiler-cli< 2.3.0这将是(例如):

MdlBadgeDirective.ctorParameters = [
        { type: ElementRef,},{ type: Renderer,];

如果软件包是用较新的版本编译的,这将是:

MdlBadgeDirective.ctorParameters = function () { return [
        { type: ElementRef,]; };

正如你可以看到更新的版本是一个函数,不再是一个数组.所以错误

ctorParameters.map is not a function

说得通.因为map是数组的成员,而是函数的成员.

如何解决这个问题?

>您可以将您的角度版本(或尝试编译您的angular2代码的软件包)更新为新的编译器输出格式.例如.至少@angular / * @ 2.3.1. (如果您使用angle-cli,您应该将您的项目升级到angular-cli@1.0.0-beta.24)
>您可以将您正在使用的软件包锁定到与旧的编译器输出格式相匹配的版本.对于angular2-mdl,这是2.7.0版本.你可以在这里找到这个信息:https://github.com/mseemann/angular2-mdl#remarks.

可以使用一个使用较新的angular-compiler-cli和较新的angular-compiler-cli版本编译的软件包? (例如,你的角度是2.4.1,想要使用angular2-mdl@2.7.0)是的!这个方向是向后兼容的.见https://github.com/angular/angular/blob/master/modules/%40angular/core/src/reflection/reflection_capabilities.ts#L80

原文链接:https://www.f2er.com/angularjs/142712.html

猜你在找的Angularjs相关文章