これをクラスにパッケージ化し、サービスとして使用できます。たとえば、次に
@Injectable()
export class SharedValues {
public Title = 'aaaaa';
public Something = 'bbbbb';
}
、あなたはRC5を使用している場合は、あなたのモジュールに含める...
import { SharedValues } from 'some/path/shared-values.service';
@NgModule({
// declarations, imports, bootstrap...
providers: [
// your other providers
SharedValues,
]
}) export class AppModule {}
あなたはRC4を使用したり、以前されている場合は、あなたのブートストラップに追加...
import { SharedValues } from 'some/path/shared-values.service';
bootstrap(AppComponent, [
// ...
SharedValues,
]);
どこでも使いたいと思っています。
import { SharedValues } from 'some/path/shared-values.service';
// or wherever you want to use the variables
@Component({
// ...
}) export class SomeComponent {
constructor(private shared: SharedValues) {
console.log(this.shared.Title, this.shared.Something);
}
}
ありがとうございます@NgModule構文はRC5でのみ機能しますか? – Shawn
はい、回答を編集してRC4も含めます – jcolemang