gpt4 book ai didi

angular - ng-bootstrap 不工作如果 'ngb-xx' 是一个 Angular 组件,那么验证它是这个模块的一部分

转载 作者:行者123 更新时间:2023-12-03 22:18:40 26 4
gpt4 key购买 nike

获取消息

If 'ngb-xx' is an Angular component, then verify that it is part of this module



对于我尝试的每个 Angular Bootstrap 组件

设置过程
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

Failed: Template parse errors: 'ngb-tab' is not a known element:

  1. If 'ngb-tab' is an Angular component, then verify that it is part of this module.

  2. If 'ngb-tab' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

("



仅加勒特

Failed: Template parse errors: Can't bind to 'dismissible' since it isn't a known property of 'ngb-alert'.

  1. If 'ngb-alert' is an Angular component and it has 'dismissible' input, then verify that it is part of this module.

  2. If 'ngb-alert' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

  3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.



请帮忙谢谢

看起来问题似乎来自业力/ Jasmine 设置

这是我的 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
});
};

最佳答案

问题在这里:

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

我可以在这里找到的另一个问题是 <template ngbTabContent>
更改 <template ngbTabContent><ng-template ngbTabContent>并且 </template></ng-template> .

WORKING DEMO

关于angular - ng-bootstrap 不工作如果 'ngb-xx' 是一个 Angular 组件,那么验证它是这个模块的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48514366/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com