小编nas*_*ngW的帖子

angular2:如何通过条件手动将css文件添加到index.html?

下面的代码是为样式定义的.

<!-- for mobile -->
<link rel="stylesheet" href="/dist/css/mobile.css">

<!-- for desktop -->    
<link rel="stylesheet" href="/dist/css/desktop.css">
Run Code Online (Sandbox Code Playgroud)

我想按条件将上面的文件添加到'src/index.html'中的<head>.

如何为每个设备应用css文件?

如您所知,我不能在'index.html'中使用'条件'代码.

请注意,我不会使用以下方法.

// in angular-cli.json
"apps": [
    {
        "root": "src",
        "index": "index.html",
        "styles": [
            "/dist/css/mobile.css",
            "/dist/css/desktop.css"
        ]
    }
]


// in component.ts
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrl: '/dist/css/mobile.css'
})
Run Code Online (Sandbox Code Playgroud)

我期待着你的建议.

谢谢.

css external angular-cli angular

5
推荐指数
1
解决办法
7496
查看次数

标签 统计

angular ×1

angular-cli ×1

css ×1

external ×1