我正在尝试使用Visual Studio将ngx-bootstraps下拉列表集成到我的SPA模板中。我有以下内容;
的package.json;
"devDependencies": {
"@angular/animations": "4.2.5",
"@angular/common": "4.2.5",
"@angular/compiler": "4.2.5",
"@angular/compiler-cli": "4.2.5",
"@angular/core": "4.2.5",
"@angular/forms": "4.2.5",
"@angular/http": "4.2.5",
"@angular/platform-browser": "4.2.5",
"@angular/platform-browser-dynamic": "4.2.5",
"@angular/platform-server": "4.2.5",
"@angular/router": "4.2.5",
"@ngtools/webpack": "1.5.0",
"@types/chai": "4.0.1",
"@types/jasmine": "2.5.53",
"@types/webpack-env": "1.13.0",
"angular2-router-loader": "0.3.5",
"angular2-template-loader": "0.6.2",
"angular2-carousel": "1.0.12",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "3.2.1",
"bootstrap": "3.3.7",
"chai": "4.0.2",
"css": "2.2.1",
"css-loader": "0.28.4",
"es6-shim": "0.35.3",
"event-source-polyfill": "0.0.9",
"expose-loader": "0.7.3",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "0.11.2",
"font-awesome": "4.7.0",
"hammerjs": "2.0.8",
"html-loader": "0.4.5",
"isomorphic-fetch": "2.2.1",
"jasmine-core": "2.6.4",
"jquery": "3.2.1",
"json-loader": "0.5.4",
"karma": "1.7.0",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "1.0.1",
"karma-jasmine": "1.1.0",
"karma-webpack": "2.0.3",
"ngx-bootstrap": "2.0.0-rc.0",
"preboot": "4.5.2",
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.10",
"rxjs": "5.4.2",
"style-loader": "0.18.2",
"to-string-loader": "1.1.5",
"typescript": "2.4.1",
"url-loader": "0.5.9",
"webpack": "3.10.0",
"webpack-hot-middleware": "2.21.0",
"webpack-merge": "4.1.1",
"zone.js": "0.8.12"
}
我已将以下内容添加到我的webpack.config.vendor.js;
const merge = require('webpack-merge');
const treeShakableModules = [
'@angular/animations',
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/forms',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'zone.js',
];
const nonTreeShakableModules = [
'bootstrap',
'bootstrap/dist/css/bootstrap.css',
'es6-promise',
'es6-shim',
'event-source-polyfill',
'font-awesome/css/font-awesome.css',
'angular2-carousel',
'hammerjs',
'ngx-bootstrap',
'jquery',
];
我运行了webpack命令(运行我的应用程序时没有错误。)
我的app.browser.module.ts是;
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppModuleShared } from './app.shared.module';
import { AppComponent } from './components/app/app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CarouselModule } from "angular2-carousel";
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
@NgModule({
bootstrap: [ AppComponent ],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppModuleShared,
CarouselModule,
BsDropdownModule.forRoot()
],
providers: [
{ provide: 'BASE_URL', useFactory: getBaseUrl }
]
})
export class AppModule {
}
export function getBaseUrl() {
return document.getElementsByTagName('base')[0].href;
}
注意我也试过了;
import { BsDropdownModule } from 'ngx-bootstrap';
在我的nav.component.ts中,我有;
import { Injectable, Inject, Component } from '@angular/core';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { APP_CONFIG, AppConfig } from '../../../app.config';
@Component({
selector: 'nav-menu',
templateUrl: './navmenu.component.html',
styleUrls: ['./navmenu.component.css']
})
export class NavMenuComponent {
constructor(@Inject(APP_CONFIG) private config: AppConfig) { }
}
和html是;
<li [routerLinkActive]="['link-active']" dropdown>
<a [routerLink]="['/services']" dropdownToggle>
Our services
</a>
<ul *dropdownMenu class="dropdown-menu" role="menu">
<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Another action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Something else here</a></li>
<li class="divider dropdown-divider"></li>
<li role="menuitem">
<a class="dropdown-item" href="#">Separated link</a>
</li>
</ul>
</li>
代码在控制台中没有出现任何错误但是下拉没有出现?当我检查chrome中的服务链接上的代码时,我得到以下html;
<li _ngcontent-c1="" dropdown="" ng-reflect-router-link-active="link-active">
<a _ngcontent-c1="" dropdowntoggle="" ng-reflect-router-link="/services" href="/services">
Our services
</a>
<!---->
</li>
有谁能告诉我哪里出错了?