簡體   English   中英

在Angular 2 +流星應用程序中包含Google字體

[英]Include Google Font in Angular 2 + Meteor Application

Newb to 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 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文件中插入此代碼,該文件放在公共文件夾中

客戶
| --app.ts
| --main.ts
| --index.html
上市
| --styles
| --common_style.css

@import url(https://fonts.googleapis.com/css?family=Montserrat);

然后在app.ts - main loader typescript文件中我已經包含了樣式

@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 ]
})

並在所有頁面上獲得了風格

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM