我有一个服务,打开一个对话框。 在该服务中,我有我想在所有应用用户之间共享的属性。 如果我在我的服务中声明它们是静态的并按如下方式使用它们:
@Injectable()
export class DialogsService {
static descriptionOptions :Array<string> =[ "Contains", "Begins with" ,"End with" ,"Equals" ];
constructor(private dialog: MdDialog , private cuntryService :CountryService ,
private mpMaterialService :MPMaterialService ) {
....
}
public openMyDialog( )
{
let dialogRef: MdDialogRef<MyDialog>;
dialogRef = this.dialog.open(MyDialog ,
{ height: '450px', width: '450px'});// define dialog size
dialogRef.componentInstance.descriptionOptions = DialogsService.descriptionOptions;
dialogRef.afterClosed().subscribe ( (response) => .....{ } );
}
}
@Component({
selector: 'MyDialog -dialog',
templateUrl: './MyDialog -dialog.html',
styleUrls: ['./MyDialog -dialog.css']
})
export class MyDialog {
descriptionOptions :Array<string>;
constructor(public dialogRef: MdDialogRef<MyDialog>)
{
console.log("MyDialog constructor");
}
closeDialog( ) {
this.dialogRef.close('return result');
}
}
descriptionOptions的静态减速是否只为所有应用用户创建一次属性?