在 Angular 2 + Meteor 应用程序中包含 Google 字体
Include Google Font in Angular 2 + Meteor Application
新手 Angular 2 .
如何在我的应用程序中包含 Google 字体。
应用程序结构是
客户
|--app.ts
|--main.ts
|--index.html
IndexFile.html
<head></head>
<body style="font-family: 'Montserrat', sans-serif;">
<div class="container-fluid">
<app-start>Loading...</app-start>
</div>
</body>
在头标签中包含 link
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
但没有效果,还在客户端文件夹 (font.js) 中创建了一个 JS 文件并插入了代码
Meteor.startup(function() {
WebFontConfig = {
google: { families: [ 'Montserrat::latin' ] }
};
(function() {
var wf = document.createElement('script');
wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
})
但是没有效果。
将此字体包含在我的 Angular 2 + Meteor 应用程序中的正确方法
使用@import 找到解决方案
将此代码插入 common_style.css 文件中,我将其放在 public 文件夹中
客户
|--app.ts
|--main.ts
|--index.html
public
|--样式
|--common_style.css
@import url(https://fonts.googleapis.com/css?family=Montserrat);
然后在 app.ts - 主加载程序打字稿文件中,我已经包含了样式
@Component({
selector:'app-start',
template:`
<div style=" font-family: 'Montserrat', sans-serif;">
<navbar></navbar>
<router-outlet></router-outlet>
<footer></footer>
</div>
`,
directives : [ NavbarComponent,FooterComponent, ROUTER_DIRECTIVES ],
providers : [ ROUTER_PROVIDERS ]
})
所有页面都有样式
新手 Angular 2 .
如何在我的应用程序中包含 Google 字体。 应用程序结构是
客户
|--app.ts
|--main.ts
|--index.html
IndexFile.html
<head></head>
<body style="font-family: 'Montserrat', sans-serif;">
<div class="container-fluid">
<app-start>Loading...</app-start>
</div>
</body>
在头标签中包含 link
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
但没有效果,还在客户端文件夹 (font.js) 中创建了一个 JS 文件并插入了代码
Meteor.startup(function() {
WebFontConfig = {
google: { families: [ 'Montserrat::latin' ] }
};
(function() {
var wf = document.createElement('script');
wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
})
但是没有效果。
将此字体包含在我的 Angular 2 + Meteor 应用程序中的正确方法
使用@import 找到解决方案
将此代码插入 common_style.css 文件中,我将其放在 public 文件夹中
客户
|--app.ts
|--main.ts
|--index.html
public
|--样式
|--common_style.css
@import url(https://fonts.googleapis.com/css?family=Montserrat);
然后在 app.ts - 主加载程序打字稿文件中,我已经包含了样式
@Component({
selector:'app-start',
template:`
<div style=" font-family: 'Montserrat', sans-serif;">
<navbar></navbar>
<router-outlet></router-outlet>
<footer></footer>
</div>
`,
directives : [ NavbarComponent,FooterComponent, ROUTER_DIRECTIVES ],
providers : [ ROUTER_PROVIDERS ]
})
所有页面都有样式