gpt4 book ai didi

Angular ng-bootstrap tabset 字段不工作

转载 作者:搜寻专家 更新时间:2023-10-30 21:46:55 26 4
gpt4 key购买 nike

    {
"name": "ModalWindow",
"version": "1.0.0",
"repository": {
"type": "git",
"url": ""
},
"scripts": {
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open"
},
"license": "MIT",
"dependencies": {
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"core-js": "^2.5.5",
"rxjs": "6.3.0",
"rxjs-compat": "^6.3.3",
"sass": "^1.15.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@ng-bootstrap/ng-bootstrap": "^1.1.1",
"@types/node": "^10.0.4",
"angular2-template-loader": "^0.6.2",
"css-loader": "^0.28.11",
"html-webpack-plugin": "^3.2.0",
"less": "^3.0.4",
"less-loader": "^4.1.0",
"node-sass": "^4.10.0",
"raw-loader": "^0.5.1",
"sass-loader": "^7.1.0",
"style-loader": "^0.21.0",
"ts-loader": "^4.3.0",
"typescript": "^2.8.3",
"webpack": "4.8.1",
"webpack-cli": "^2.1.3",
"webpack-dev-server": "3.1.4"
}
}

这是我的 package.json,我不明白哪里出了问题,但 ng-bootstrap 中的标签集无法正常工作。

最佳答案

最新版本 4.0.0 和您在 package.json 中使用的版本(即 ^1.1.1)之间的主要区别在于,在最新版本中没有必要导入NgbModule作为NgbModule.forRoot() .例如-

此代码适用于版本 4.x.x

@NgModule({
imports: [BrowserModule, FormsModule, ReactiveFormsModule, HttpClientModule, NgbModule],
declarations: [....],
bootstrap: [...]
})

但是如果你导入NgbModule如上所示,在您使用的 1.1.1 版本中,您将得到以下错误

ERROR Error: StaticInjectorError(AppModule)[NgbTabset -> NgbTabsetConfig]: StaticInjectorError(Platform: core)[NgbTabset -> NgbTabsetConfig]: NullInjectorError: No provider for NgbTabsetConfig!

那是因为低版本需要用.forRoot()在您的根模块中,以使其在您应用程序的所有其他模块和组件中可用。

因此对于您使用的版本 1.1.1,您需要在根模块中使用以下代码 app.module.ts

此代码适用于 1.1.1 版本

@NgModule({
imports: [BrowserModule, FormsModule, ReactiveFormsModule, HttpClientModule, NgbModule.forRoot()],
declarations: [AppComponent, NgbdTabsetBasic],
bootstrap: [AppComponent]
})

这是 Angular 5 和您正在使用的 ng-bootstrap 版本 1.1.1 的完整示例 -

package.json(和你用的一样)

{
"name": "ModalWindow",
"version": "1.0.0",
"repository": {
"type": "git",
"url": ""
},
"scripts": {
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open"
},
"license": "MIT",
"dependencies": {
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"@ng-bootstrap/ng-bootstrap": "1.1.1",
"core-js": "^2.5.5",
"rxjs": "6.3.0",
"rxjs-compat": "^6.3.3",
"sass": "^1.15.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@types/node": "^10.0.4",
"angular2-template-loader": "^0.6.2",
"css-loader": "^0.28.11",
"html-webpack-plugin": "^3.2.0",
"less": "^3.0.4",
"less-loader": "^4.1.0",
"node-sass": "^4.10.0",
"raw-loader": "^0.5.1",
"sass-loader": "^7.1.0",
"style-loader": "^0.21.0",
"ts-loader": "^4.3.0",
"typescript": "^2.8.3",
"webpack": "4.8.1",
"webpack-cli": "^2.1.3",
"webpack-dev-server": "3.1.4"
}
}

app.component.html

<div class="container-fluid">
<ngbd-tabset-basic></ngbd-tabset-basic>
</div>

app.component.ts

import { Component } from '@angular/core';

@Component({
selector: 'my-app',
templateUrl: './app.component.html'
})
export class AppComponent {
}

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { AppComponent } from './app.component';
import { NgbdTabsetBasic } from './tabset-basic';

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

tabset-basic.html

<ngb-tabset>
<ngb-tab title="Simple">
<ng-template ngbTabContent>
<p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth
master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh
dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum
iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
</ng-template>
</ngb-tab>
<ngb-tab>
<ng-template ngbTabTitle><b>Fancy</b> title</ng-template>
<ng-template ngbTabContent>Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid.
<p>Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table
craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl
cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia
yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean
shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero
sint qui sapiente accusamus tattooed echo park.</p>
</ng-template>
</ngb-tab>
<ngb-tab title="Disabled" [disabled]="true">
<ng-template ngbTabContent>
<p>Sed commodo, leo at suscipit dictum, quam est porttitor sapien, eget sodales nibh elit id diam. Nulla facilisi. Donec egestas ligula vitae odio interdum aliquet. Duis lectus turpis, luctus eget tincidunt eu, congue et odio. Duis pharetra et nisl at faucibus. Quisque luctus pulvinar arcu, et molestie lectus ultrices et. Sed diam urna, egestas ut ipsum vel, volutpat volutpat neque. Praesent fringilla tortor arcu. Vivamus faucibus nisl enim, nec tristique ipsum euismod facilisis. Morbi ut bibendum est, eu tincidunt odio. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Mauris aliquet odio ac lorem aliquet ultricies in eget neque. Phasellus nec tortor vel tellus pulvinar feugiat.</p>
</ng-template>
</ngb-tab>
</ngb-tabset>

tabset-basic.ts

import {Component} from '@angular/core';

@Component({
selector: 'ngbd-tabset-basic',
templateUrl: './tabset-basic.html'
})
export class NgbdTabsetBasic { }

注意事项:

我们需要添加 Bootstrap 4.0 css 作为依赖。可以通过以下两种方式添加 css - 1.添加一个<link>index.html 中使用样式表标记页 2. 如果您使用的是 angular-cli,则可以将其添加到 styles 中节.angular-cli.json

这样的文件
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
]

这是一个完整的工作演示 https://stackblitz.com/edit/angular-wfkcak

更新:通过您的 stackblitz 链接后,我发现您忘记添加 bootstrap 4 CSS 文件。我已将其添加到 index.html 中文件。

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

您也可以将其添加到 angular.json (对于 Angular 6 )或 .angular-cli.json (对于 Angular 5 )在 styles 下适用于您上面提到的数组。

这是更新的 stackblitz https://stackblitz.com/edit/angular-gmedf1

关于Angular ng-bootstrap tabset 字段不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53339926/

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