我有一个包含许多输入的页面,我想让它' readOnly'我找到这个解决方案:如何在Angular2 Typescript中更改HTML元素readonly和required属性?
但是我不想单独为每个输入做这件事.
如何readOnly在某个div中为所有输入添加属性.
我想创建服务,它可以与一个组件进行交互.我的应用程序中的所有其他组件应该能够调用此服务,并且此服务应该与此组件交互.
如何从服务中调用组件方法?
@Component({
selector:'component'
})
export class Component{
function2(){
// How call it?
}
}
Run Code Online (Sandbox Code Playgroud)
从这个服务?
@Injectable()
export class Service {
callComponentsMethod() {
//From this place?;
}
}
Run Code Online (Sandbox Code Playgroud) typescript angular2-services angular2-injection angular2-components angular
我有抽象类(没有构造函数),我想在其中注入另一个类.
抽象类:
import { ErrorHandler } from '../../shared/services/errorHandler.service';
import { Inject } from '@angular/core';
export abstract class BaseApiComponent<T> {
@Inject(ErrorHandler) errorHandler: ErrorHandler;
this.errorHandler.test();
}
Run Code Online (Sandbox Code Playgroud)
注入课程:
import { Injectable } from '@angular/core';
@Injectable()
export class ErrorHandler {
constructor() { }
public test() {
console.log('Test');
}
}
Run Code Online (Sandbox Code Playgroud)
我有下一个错误
ORIGINAL EXCEPTION: TypeError: Cannot read property 'test' of undefined
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?
我想用moment.js改变一些时间.
我有下一次:Tue May 16 2017 15:34:23 GMT+0300 (FLE Daylight Time),我想把它改成11.11例如.
时间应该是Tue May 16 2017 11:11:23 GMT+0300 (FLE Daylight Time).
我该如何实现呢?
我想在父模块中声明管道并在子模块中使用它.
@NgModule({
// Pipe which I want to declare in all child modules
declarations: [ ThisIsPipe ],
imports: [ ChildModuleOne, ChildModuleTwo],
})
Run Code Online (Sandbox Code Playgroud)
我该如何使用It子模块?
因为如果我宣布它两次我就会收到错误
未捕获错误:类型ThisIsPipe是2个模块声明的一部分:ChildModuleOne和ChildModuleTwo!请考虑将ThisIsPipe移动到导入ChildModuleOne和ChildModuleTwo的更高模块.您还可以创建一个新的NgModule,它导出并包含ThisIsPipe,然后在ChildModuleOne和ChildModuleTwo中导入NgModule.
我正在使用subject作为我的angular2应用程序中组件的通信服务的服务.
通话方式:
this.notification.create('test');
Run Code Online (Sandbox Code Playgroud)
服务:
export class NotificationService {
private static notificationSource = new Subject<any>()
notiCreated$ = NotificationService.notificationSource.asObservable();
create(message) {
NotificationService.notificationSource.next(message);
}
}
Run Code Online (Sandbox Code Playgroud)
被叫功能:
this.subscription = notification.notiCreated$.subscribe(
data => {
console.log(data);
this.createNotification(data, 'warning');
});
Run Code Online (Sandbox Code Playgroud)
但我想通过2个参数.我有错误.
我该怎么做?
我想在我的Angular 6应用程序中使用ngxs进行状态管理.
但我不确定大项目是否成熟.
我找不到任何关于ngrx和ngxs之间性能差异的文章.有人可以提供一些信息吗?
性能指标:从商店中获取大量商品并将其写回商店.
如何将动态名称设置为angular 2组件?
我的模板中有下一个代码:
<{{component} [data]="data" [anotherData]="anotherData"></{{component}}>
Run Code Online (Sandbox Code Playgroud)
我想在类中定义componentName
component: string = 'component';
Run Code Online (Sandbox Code Playgroud)
因为现在我有下一个错误:
Uncaught (in promise): Template parse errors:
Unexpected closing tag "{{component}" ("
Run Code Online (Sandbox Code Playgroud) 我有一个代码 <div class="flex-container" *ngIf="mail"> Some data </div>
我有一个错误 Can't bind to 'ngIf' since it isn't a known property of 'div'.
我怎么解决它?
如何在组件渲染后从指令调用函数?
我有组件:
export class Component {
ngAfterContentInit() {
// How can i call functionFromDirective()?
}
}
Run Code Online (Sandbox Code Playgroud)
我想要调用这个函数:
export class Directive {
functionFromDirective() {
//something hapenns
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?