简体   繁体   English

将ng-boostrap添加到Angular应用不会对HTML控件产生影响

[英]Adding ng-boostrap to Angular app makes no effect on HTML controls

I have recently tried adding ng-bootstrap to my asp.net mvc with Angular app. 我最近尝试使用Angular应用将ng-bootstrap添加到我的asp.net mvc中。 I followed the steps at ng-bootstrap and I can't get it to work. 我按照ng-bootstrap的步骤操作,但无法正常工作。 The controls look like plain html (like I didn't use ng-boostrap at all) I would appreciate any help. 控件看起来像纯HTML(就像我根本没有使用ng-boostrap一样),我将不胜感激。

main.ts main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';

platformBrowserDynamic().bootstrapModule(AppModule);

systemjs.config.js systemjs.config.js

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
    System.config({
        paths: {
            // paths serve as alias
            'npm:': '/node_modules/'
        },
        // map tells the System loader where to look for things
        map: {
            // our app is within the app folder
            'app': '/src/app',

            // angular bundles
            '@angular/animations': 'npm:@angular/animations/bundles/animations.umd.js',
            '@angular/animations/browser': 'npm:@angular/animations/bundles/animations-browser.umd.js',
            '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
            '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
            '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
            '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
            '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
            '@angular/platform-browser/animations': 'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js',
            '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
            '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
            '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
            '@ng-bootstrap/ng-bootstrap': 'npm:@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js',
            // other libraries
            'rxjs': 'npm:rxjs',
            'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
            'tslib': 'npm:tslib/tslib.js',
            'bootstrap':                  'node_modules/bootstrap/dist/js/bootstrap.min.js',
            'jquery':                     'node_modules/jquery/dist/jquery.js',

            '@progress': 'npm:@progress',
            '@telerik': 'npm:@telerik'
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: {
                defaultExtension: 'js',
                meta: {
                    './*.js': {
                        loader: '/src/systemjs-angular-loader.js'
                    }
                }
            },
            rxjs: {
                defaultExtension: 'js'
            }
        }
    });
})(this);

app.module.ts app.module.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent }  from './app.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';

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

app.component.ts app.component.ts

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

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

app.component.html app.component.html

<div class="row">
    <div class="col">
        <h1>Angular</h1>
        <div ngbDropdown class="d-inline-block">
            <button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle>Toggle dropdown</button>
            <div ngbDropdownMenu aria-labelledby="dropdownBasic1">
                <button class="dropdown-item">Action - 1</button>
                <button class="dropdown-item">Another Action</button>
                <button class="dropdown-item">Something else is here</button>
            </div>
        </div>
    </div>
</div>

According to the ng-bootstrap documentation , you should not include bootstrap.min.js and jQuery in your project because 根据ng-bootstrap文档 ,您不应在项目中包含bootstrap.min.jsjQuery ,因为

It is not necessary and might interfere with ng-bootstrap code. 这不是必需的,并且可能会干扰ng-bootstrap代码。

But the main issue is that you didn't include NgbdDropdownBasic into your App module declarations: 但是主要的问题是您没有在App模块声明中包含NgbdDropdownBasic

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent }  from './app.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { NgbdDropdownBasic } from './dropdown-basic'; // this

@NgModule({
  imports: [BrowserModule, BrowserAnimationsModule, NgbModule.forRoot()],
  declarations: [ AppComponent, NgbdDropdownBasic ], // and this
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

Each ng-bootstrap entity should be included separately. 每个ng-bootstrap实体都应单独包含。 Want to use Datepicker? 要使用Datepicker? include NgbdDatepickerBasic , and so on... 包括NgbdDatepickerBasic ,依此类推...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有 ng-boostrap 和 Angular 2 的旋转木马动画 - Animation for carousel with ng-boostrap and Angular 2 无法使用 Angular 和对等 js 安装 ng-boostrap - Can't intall ng-boostrap with Angular and peer js 使用自定义 angular 指令扩展 ng-boostrap 弹出框组件 - Extend ng-boostrap popover component with custom angular directive 移动鼠标时,带有嵌入式视频的ng-boostrap模态将重新加载 - Angular ng-boostrap modal with an embeded video reloads when mouse is moved Boostrap和Angular的ng-include指令 - Boostrap and Angular's ng-include directive Angular.js应用程序在ng-repeat中合并无限摘要循环,并使网站不负责任 - Angular.js app cousing inifinite digest loop within ng-repeat and makes site unresponsible 将ngAnimate添加到控制器会使应用程序不显示内容 - adding ngAnimate to controller makes app to not displaying content 如何添加JavaScript背景效果来禁用元素中的控件? - How can adding a JavaScript background effect disable controls in my element? 在将“UI网格”添加到应用程序后,Angular $ httpProvider拦截器停止为“ng-include”工作 - Angular $httpProvider interceptors stopped working for 'ng-include' after adding “UI Grid” to the app 新的表单控件未添加到 Angular 7 反应式表单中 - New Form Controls are not adding in Angular 7 reactive forms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM