思路
1.创建一个server 里面写上自己常用的一些变量
2.在页面中直接绑定绑定形式为{{strings.user.name}}
这样的形式来绑定
不说了直接上代码了
//SettingsService
import { Injectable } from '@angular/core';
declare var $: any;
@Injectable()
export class SettingsService {
public user: any;
public app: any;
public layout: any;
public bodyHeight: string;
constructor() {
// User Settings
// -----------------------------------
this.user = {
name: 'John',
job: 'ng-developer',
picture: 'assets/img/user/02.jpg'
};
// App Settings
// -----------------------------------
this.app = {
name: 'angular 4',
year: ((new Date()).getFullYear())
};
// Layout Settings
// -----------------------------------
this.layout = {
isFixed: true,
isCollapsed: false,
isBoxed: false,
isRTL: false,
horizontal: false,
isFloat: false,
asideHover: false,
theme: null,
asideScrollbar: false,
isCollapsedText: false,
useFullLayout: false,
hiddenFooter: false,
offsidebarOpen: false,
asideToggled: false,
viewAnimation: 'ng-fadeInUp'
};
}
}
组件调用
//Footer.Component.ts
import { Component, OnInit } from '@angular/core';
import { SettingsService } from '../../core/settings/settings.service';
@Component({
selector: '[footer]',
templateUrl: './footer.component.html',
styleUrls: ['./footer.component.scss']
})
export class FooterComponent implements OnInit {
constructor(public settings: SettingsService) { }
ngOnInit() {
}
}
//Footer.Component.html
<span>© {{settings.user.name}} - {{ settings.user.job}}</span>
网友评论