【问题标题】:ng-boostrap not workingIf 'ngb-xx' is an Angular component, then verify that it is part of this moduleng-bootstrap 不工作如果 'ngb-xx' 是一个 Angular 组件,那么验证它是这个模块的一部分
【发布时间】:2018-07-08 22:07:54
【问题描述】:

收到消息

如果 'ngb-xx' 是 Angular 组件,则验证它是 这个模块

对于我尝试的每个角度引导组件

设置过程

npm install angular-cli
ng new project 
npm install 
npm install  --save bootstrap 
npm install --save @ng-bootstrap/ng-bootstrap

在 app.module.ts 中

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http' ;

import { NgbModule } from '@ng-bootstrap/ng-bootstrap' ;

import { AppComponent } from './app.component';
import { NgForm } from '@angular/forms/src/directives/ng_form';


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    NgbModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

在 .angular-cli.json 中

  "styles": [
    "styles.css", 
    "../node_modules/bootstrap/dist/css/bootstrap.min.css"
  ],

甚至尝试添加 npm install --save jquery 并在 .angular-cli.json 中

  "scripts": [ 
    "../node_modules/jquery/dist/jquery.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js"
  ],

在app.component.html中添加

  <ngb-tabset> 
      <ngb-tab title="test">
        <template ngbTabContent> 
            xxx ss
        </template>
      </ngb-tab>

      <ngb-tab title="test">
          <template ngbTabContent> 
              xxxs ss
          </template>
        </ngb-tab>
  </ngb-tabset>
<p>
  <ngb-alert [dismissible]="false">
    <strong>Warning!</strong> Better check yourself, you're not looking too good.
  </ngb-alert>
</p>

css 似乎可以工作,但业力错误且没有 js

失败:模板解析错误:“ngb-tab”不是已知元素:

  1. 如果 'ngb-tab' 是 Angular 组件,则验证它是该模块的一部分。

  2. 如果“ngb-tab”是 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以禁止显示此消息。

("

只限警告

失败:模板解析错误:无法绑定到“dismissible”,因为它 不是“ngb-alert”的已知属性。

  1. 如果 'ngb-alert' 是一个 Angular 组件并且它具有 'dismissible' 输入,则验证它是该模块的一部分。

  2. 如果“ngb-alert”是一个 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以禁止显示此消息。

  3. 要允许任何属性将“NO_ERRORS_SCHEMA”添加到此组件的“@NgModule.schemas”。

请帮忙谢谢

看起来问题似乎来自业力/茉莉花设置

这是我的 karma.conf.js

// Karma 配置文件,更多信息见链接 //https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

【问题讨论】:

  • 您的代码绝对没问题,请分享您使用的代码ngb-tab
  • 嗨 @VivekDoshi 感谢刚刚添加到内容中
  • 嗨@VivekDoshi 谢谢你的回答演示让我走上了正确的轨道看起来这里真正的问题似乎是业力/茉莉花设置,因为应用程序正在自行运行,但业力/茉莉花正在抛出错误

标签: angular twitter-bootstrap angular-cli ng-bootstrap


【解决方案1】:

问题在这里:

npm install angular-cli
ng new project 
npm install 
npm install  --save bootstrap 
npm install --save @ng-bootstrap/ng-bootstrap

创建项目后忘记进入目录

npm install angular-cli
ng new project 
cd 'project' // <-------------- Here , you missed this
npm install 
npm install  --save bootstrap 
npm install --save @ng-bootstrap/ng-bootstrap

我可以在这里找到的另一个问题是&lt;template ngbTabContent&gt;

&lt;template ngbTabContent&gt; 更改为&lt;ng-template ngbTabContent&gt; 以及 &lt;/template&gt;&lt;/ng-template&gt;

WORKING DEMO

【讨论】:

  • 看起来应用程序正在独立运行,但 karma/jasmine 出现错误可能是我缺少设置它的配置
  • 如果您修改答案以帮助 karma jasmine 配置,我将接受答案
【解决方案2】:

终于找到问题了

在安装和配置模块时不要忘记插入到 test.spec.ts

import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap' ; 
import { BrowserModule } from '@angular/platform-browser';

describe('AppComponent', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        NgbModule.forRoot()
      ],
    }).compileComponents();
  }));

【讨论】:

    猜你喜欢
    • 2017-10-11
    • 2021-04-20
    • 2023-03-03
    • 2021-11-11
    • 2021-01-23
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    • 2021-12-02
    相关资源
    最近更新 更多