关于angular–Ionic3导入自定义组件和angular引入组件的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Angular2RC2如何将路由器注入自定义ExceptionHand
关于angular – Ionic 3导入自定义组件和angular引入组件的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Angular 2 RC 2如何将路由器注入自定义ExceptionHandler、angular – Ionic 3不能在我的自定义组件中使用ion- *组件、angular – 如何使用按钮样式在Ionic 2中创建自定义文件输入?、angular – 如何在Ionic 2/3中编写自定义组件而不会丢失准备好的CSS?等相关知识的信息别忘了在本站进行查找喔。
本文目录一览:- angular – Ionic 3导入自定义组件(angular引入组件)
- Angular 2 RC 2如何将路由器注入自定义ExceptionHandler
- angular – Ionic 3不能在我的自定义组件中使用ion- *组件
- angular – 如何使用按钮样式在Ionic 2中创建自定义文件输入?
- angular – 如何在Ionic 2/3中编写自定义组件而不会丢失准备好的CSS?
angular – Ionic 3导入自定义组件(angular引入组件)
我有一个名为other的现有页面模块.运行离子g组件测试后,我将自动生成的ComponentsModule导入other.module.ts并将其添加到imports数组中.
import { ComponentsModule } from "../../components/components.module"; @NgModule({ declarations: [ OtherPage,],imports: [ IonicPageModule.forChild(OtherPage),ComponentsModule,}) export class OtherPageModule {}
然后,我将组件选择器添加到页面中< test>< / test>.
这会导致错误:
polyfills.js:3 Unhandled Promise rejection: Template parse errors: 'test' is not a kNown element: 1. If 'test' is an Angular component,then verify that it is part of this module. 2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. (" <ion-content padding> [ERROR ->]<test> </test> </ion-content> "): ng:///AppModule/OtherPage.html@16:0 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors: 'test' is not a kNown element: 1. If 'test' is an Angular component,then verify that it is part of this module.
这对我不起作用.我还尝试为测试组件创建一个模块并以相同的方式导入它,但这对我不起作用.
我似乎无法找到任何文档或示例.如何在Ionic 3中导入自定义组件?
解决方法
import { ComponentsModule } from "../../components/components.module"; @NgModule({ declarations: [ OtherPage,entryComponents: [ ComponentsModule ] }) export class OtherPageModule {}
Angular 2 RC 2如何将路由器注入自定义ExceptionHandler
Error: Error: Cannot resolve all parameters for ‘ErrorHandler'(?).
Make sure that all the parameters are decorated with Inject or have
valid type annotations and that ‘ErrorHandler’ is decorated with
Injectable.
我确实试过装饰私有路由器:使用@Inject的路由器无济于事.我正在使用打字稿,因此我认为我不需要@Inject属性.
我的自定义ExceptionHandler看起来像这样
import { ExceptionHandler } from '@angular/core'; import { Router } from '@angular/router'; export class ErrorHandler extends ExceptionHandler{ constructor( private router: Router ){ super(null,null); } call(error,stackTrace = null,reason = null) { console.log(error); this.router.navigate(['/error']); } }
我的主要看起来像这样
import { bootstrap } from '@angular/platform-browser-dynamic'; import { AppComponent } from './app.component'; import { provide,ExceptionHandler } from '@angular/core'; import { ErrorHandler } from './error-handler/error-handler'; import { HTTP_PROVIDERS } from '@angular/http'; import { ROUTER_PROVIDERS } from '@angular/router'; bootstrap(AppComponent,[ HTTP_PROVIDERS,ROUTER_PROVIDERS,provide(ExceptionHandler,{useClass: ErrorHandler}) ]);
为什么我收到此错误?在ExceptionHandler实例化时,路由器是否可注入?
完整的源代码可在此处获得
https://github.com/harindaka/angular2-seed-typescript/tree/b368315ce6608085f3154a03bc53f0404ce16495
解决方法
import { ErrorHandler,Injectable } from '@angular/core'; @Injectable() export class GlobalErrorHandler implements ErrorHandler { private myService: MyService; constructor(private injector: Injector) { this.myService = injector.get(MyService); } handleError(error) { alert('Bad things happening'); } } @NgModule({ providers: [ { provide: ErrorHandler,useClass: GlobalErrorHandler } ] }) export class AppModule { }
注意:上面的答案使用ExceptionHandler,它在最终版本中被删除,有利于ErrorHandler.
angular – Ionic 3不能在我的自定义组件中使用ion- *组件
所以现在的问题是我不能在我自己的组件中使用ion- *组件,因为我没有在components.module中导入IonicModule.forRoot(..).
错误是:
“Template parse errors: ‘ion-spinner’ is not a kNown element …”
我究竟做错了什么?
我需要的只是在components.module中导入IonicModule,而不是forRoot(..).
另请注意,Angular的CommonModule也是使Angular的指令有效所必需的,因此您可能也需要导入它.
angular – 如何使用按钮样式在Ionic 2中创建自定义文件输入?
<label>{{label}}</label> <input type="file" (change)="fileUpload($event)" id="file-input"#fileInp> <button ion-button (click)="onClick()">Upload</button>
和ts文件:
@ViewChild('fileInp') fileInput: ElementRef; @input() label: string; @Output() data = new EventEmitter<FormData>(); fileUpload(event) { let fd = new FormData(); fd.append('file',event.srcElement.files[0]); this.data.emit(fd); } onClick() { this.fileInput.nativeElement.click(); }
在Android和浏览器中一切正常,但在iOS上则不行.
如果我禁用模板中的按钮,相同的代码将起作用.
<ion-item> <label>{{label}}</label> <input type="file" (change)="fileUpload($event)" id="file-input"#fileInp> <button ion-button (click)="onClick()">Upload</button> </ion-item>
然后在.scss文件中:
#file-input { opacity: 0; position: absolute; top: 0; width: 100%; height: 100%; left: 0; z-index: 999; }
可能还有其他一些方法可以解决这个问题,但这就是我在过去使用的应用程序上管理的方式.
angular – 如何在Ionic 2/3中编写自定义组件而不会丢失准备好的CSS?
import { Component } from '@angular/core'; @Component({ selector: 'deletableItem',template: ` <ion-checkBox item-right></ion-checkBox> ` }) export class DeletableItem { constructor() {} }
并在一些html视图中使用它:
<ion-content padding> <ion-list> <ion-item *ngFor="let bill of bills" (click)="openEdit(bill)"> <ion-label text-left>{{bill.name}}</ion-label> <deletableItem></deletableItem> </ion-item> </ion-list> </ion-content>
看起来比仅仅把它放在父的组件视图中更糟糕,如下所示:
<ion-content padding> <ion-list> <ion-item *ngFor="let bill of bills" (click)="openEdit(bill)"> <ion-label text-left>{{bill.name}}</ion-label> <ion-checkBox item-right></ion-checkBox> </ion-item> </ion-list> </ion-content>
这一切都是因为将此组件的HTML代码角度包装成html标签.所以我们失去了离子成分的强度(准备好了css).请不要建议属性组件分配如下:
<ion-checkBox item-right deletableItem></ion-checkBox>
因为这只是一个简单的例子.
在不丢失准备好的CSS的情况下,用离子组件编写自定义组件的最佳方法是什么?
解决方法
当您创建< deletableItem>< / deletableItem>时你应该模仿离子团队用离子复选框做的事情,并创建你的Sass文件.
查看源文件夹here以获取< ion-checkBox>.
为deleteableItem定义自己的SASS.
此外,on the Ionic website you can find the various SASS component/platform variables.
我还提供了一个详细的相关解释,关于Ionic CSS classes assignment也可能对你有所帮助.
您还可以使用Chrome检查在Developer工具中查看ion-checkBox的类分配,并将它们与Ionic网站上的列表进行比较.
关于angular – Ionic 3导入自定义组件和angular引入组件的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Angular 2 RC 2如何将路由器注入自定义ExceptionHandler、angular – Ionic 3不能在我的自定义组件中使用ion- *组件、angular – 如何使用按钮样式在Ionic 2中创建自定义文件输入?、angular – 如何在Ionic 2/3中编写自定义组件而不会丢失准备好的CSS?的相关知识,请在本站寻找。
本文标签: