Ionic 自定義組件中使用 Ionic 官方組件
阿新 • • 發佈:2018-04-15
article angular show searchbar known 問題 ear wan 方案
問題起因:
在項目目錄中使用 ionic g component SearchBar 加入一個新的自定義組件並在 html 中插入代碼:
1 <div> 2 <ion-searchbar 3 [(ngModel)]="myInput" 4 showCancelButton="true" 5 placeholder="輸入代碼或簡稱" 6 ></ion-searchbar> 7 </div>
此時運行報錯 ion-searchbar is not a known elements。經過一翻搜索之後找到可行的解決方案如下:
在 components.module.ts 的頭部加入:
1 import { BrowserModule } from "@angular/platform-browser"; 2 import { IonicModule } from "ionic-angular";
然後在 NgModule 的 imports 段中加入:
1 BrowserModule, IonicModule.forRoot(SearchbarComponent)
然後保存好再重新運行,即可看到正確的結果。
原文參考地址:http://www.ionic.wang/article-index-id-113.html
Ionic 自定義組件中使用 Ionic 官方組件