材质中具有angular6的可扩展搜索栏

时间:2018-06-14 05:58:01

标签: angular material-design searchbar

我想添加像this这样的expandile搜索栏。我尝试在我的angular6项目中使用此插件,但导入此插件后我得到以下错误

Date: 2018-06-14T05:18:56.196Z
Hash: 14ad16d79d2d3f70ecc8
Time: 30024ms
chunk {main} main.js, main.js.map (main) 1.97 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 661 bytes [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 5.22 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 98.1 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 325 kB [initial] [rendered]

ERROR in node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.
node_modules/ng-mat-search-bar/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.

i 「wdm」: Failed to compile.
i 「wdm」: Compiling...

以下是我的package.json文件

{
  "name": "my-dream-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/cdk": "^6.2.1",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/material": "^6.2.1",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "@material/button": "^0.36.0",
    "@material/layout-grid": "^0.34.0",
    "@ngu/carousel": "^1.4.8",
    "angular-highcharts": "^6.1.4",
    "angular4-carousel": "^3.1.8",
    "core-js": "^2.5.4",
    "highcharts": "^6.1.0",
    "material-responsive-grid": "^1.1.1",
    "ng-mat-search-bar": "^1.0.0-rc.1",
    "ng2-carouselamos": "^3.2.0",
    "ngx-hm-carousel": "^1.1.0-bata.1",
    "ngx-owl-carousel": "^2.0.7",
    "rxjs": "^6.0.0",
    "ui-carousel": "^0.2.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.6",
    "@angular/cli": "~6.0.7",
    "@angular/compiler-cli": "^6.0.3",
    "@angular/language-service": "^6.0.3",
    "@types/highcharts": "^5.0.22",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2",
    "webpack": "^4.11.1"
  }
}

请有人帮助我。还有其他这样的插件吗?或者这个错误是什么。我没有使用像bootstrap这样的任何框架我只想使用angular6或材料来实现它。请帮忙。

1 个答案:

答案 0 :(得分:0)

这是我想出的:

.html

<div class="search-container" [ngClass]="{'hasValue':hasValue}">
            <mat-form-field floatLabel="never" >
                <input matInput type="search" [(ngModel)]="term" 
              placeholder="Search&hellip;" autocomplete="off"
             (blur)="hasValue=term?true:false">
            </mat-form-field>
            <button type="button" class="searchIcon" mat-icon-button 
            (click)="hasValue=!hasValue">
              <mat-icon *ngIf="!hasValue" class="mat-18">search</mat-icon>
              <mat-icon *ngIf="hasValue" (click)="term=''" class="mat-18 
             ">close</mat-icon>
             </button>
        </div>

.ts

 term:string;
 hasValue:boolean;

.scss

.search-container{
max-width: 500px;
.mat-form-field{
  font-size:14px;
  line-height: 0.9em;
  -webkit-transition: width 0.4s ease-in-out;
  transition: width 0.4s ease-in-out;
  width: 0px;
}
}

.hasValue{
  .mat-form-field{
    width: 300px;
  }

  .searchIcon{
    background:#e2e9eb;
  }
}
相关问题