如何更改我的页面在Angular2中引用的styleshseet?

时间:2016-05-09 18:59:19

标签: angular

我希望能够通过Angular2(例如,style2.css)更改<link>元素中的样式表。鉴于该元素不是<ng2-app>元素(Angular2操作的部分)的一部分,这可能吗?

<html>
  <head>
    <link rel="stylesheet" href="style.css">
  </head>
  <ng2-app>

    <div class="loading">Loading&#8230;</div>
    <div style="text-align: center;clear: both;" class="md-headline">Application Loading....</div>

  </ng2-app>

</html>

1 个答案:

答案 0 :(得分:1)

Angular 2正在使用视图封装来规范样式表之间的相互作用。

#!/bin/bash

if [ "$1" != "" ]; then
   uid=$1
   echo "Positional parameter 1 contains something $1"
else
   echo "Positional parameter 1 is empty"
fi

LOG_TMP="tmp_log_file_location"

log_location="log_file_location"

filename="${log_location}/$uid.tar.gz"
echo $filename
tar -zcvf $filename -C $LOG_TMP/dc .

要更改全局样式表:

plunker

 @Component({
 selector:'my-app'
 templateUrl:'card.html',
 styleUrls: ['stylesheet.css'],
 encapsulation: ViewEncapsulation.Native
 //encapsulation: ViewEncapsulation.None
 //encapsulation: ViewEncapsulation.Emulated is default 
})