如果&nbsp-template&#39;是一个Web组件,然后添加&#34; CUSTOM_ELEMENTS_SCHEMA&#34;对此组件的抑制此消息。 (&#34; [错误 - &gt;] <ng-template>

时间:2017-04-10 08:35:56

标签: angular typescript angularjs-directive

  

zone.js@0.6.25?main = browser:355未处理的Promise拒绝:模板解析错误:   &#39; NG-模板&#39;不是一个已知的元素:   1.如果&nbsp-template&#39;是一个Angular组件,然后验证它是否是此模块的一部分。   2.如果&#39; ng-template&#39;是一个Web组件,然后添加&#34; CUSTOM_ELEMENTS_SCHEMA&#34;到了&#39; @ NgModule.schemas&#39;此组件禁止此消息。 (&#34; [ERROR - &gt;];任务:Promise.then;值:错误:模板解析错误:   &#39; NG-模板&#39;不是一个已知元素:

我在我的App.module.ts中应用了这个FIX:

import { NgModule, CUSTOM_ELEMENTS_SCHEMA ,NO_ERRORS_SCHEMA}  from '@angular/core';


@NgModule({
    imports: [
        BrowserModule,
        FormsModule,
        ReactiveFormsModule,
        HttpModule,
        JsonpModule,
        CKEditorModule,
        Ng2DatetimePickerModule,
        Ng2DragDropModule,
        DragulaModule,
        ModalModule.forRoot(),
        MaterialModule.forRoot(),
        BootstrapModalModule,
        RouterModule.forRoot(appRoutes, {useHash: true})
    ],
    declarations: [something
    ],
    providers: [],
    bootstrap: [AppComponent],
    schemas: [ CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA ]
})

PACKAGES.JSON

"dependencies": {
    "@angular/common": "2.2.1",
    "@angular/compiler": "2.2.1",
    "@angular/core": "2.2.1",
    "@angular/forms": "2.2.1",
    "@angular/http": "2.2.1",
    "@angular/platform-browser": "2.2.1",
    "@angular/platform-browser-dynamic": "2.2.1",
    "@angular/router": "3.2.1",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "jquery": "~3.1.1",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },



"devDependencies": {
    "@angular/compiler-cli": "2.2.1",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.21",
    "codelyzer": "~1.0.0-beta.3",
    "jasmine-core": "2.5.2",
    "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.3",
    "webdriver-manager": "10.2.5"
  }

即使在此之后它也无法正常工作。

2 个答案:

答案 0 :(得分:11)

Angular4中引入了

<ng-template>

用户<template><ng-container>

另见

答案 1 :(得分:0)

  1. 更新angular-cli:https://github.com/angular/angular-cli/wiki/stories-1.0-update
  2. 更新打字稿和可选的@angular个包。你的软件包非常落后,最重要的是angular-cli,所以要做好准备。
    • 我的核心套餐:
  3. &#13;
    &#13;
    dependecies: {
      "@angular/animations": "^4.0.2",
      "@angular/common": "^2.3.1",
      "@angular/compiler": "^2.3.1",
      "@angular/compiler-cli": "^2.4.10",
      "@angular/core": "^2.3.1",
      "@angular/forms": "^2.3.1",
      "@angular/http": "^2.3.1",
      "@angular/material": "^2.0.0-beta.3",
      "@angular/platform-browser": "^2.3.1",
      "@angular/platform-browser-dynamic": "^2.3.1",
      "@angular/platform-server": "^4.0.0",
      "@angular/router": "^3.3.1"
    }
    devDependencies: {
      "@angular/cli": "^1.0.0",
      "typescript": "^2.2.2"
    }
    &#13;
    &#13;
    &#13;

    1. npm install @angular/material && npm install hammerjs —-save
      • /node_modules/hammerjs/hammer.js
      • 中添加angular-cli.json
    2. MaterialModule已弃用https://github.com/angular/material2/releases
      • 将单个模块导入app.module,然后相应地导出,然后只需将标签添加到html