【发布时间】:2016-03-29 14:13:24
【问题描述】:
由于 Angular 2.x 是在 body 内部引导的,我如何在 body 标记上添加 [class.fixed]="isFixed"(在我的应用程序之外)?
<html>
<head>
</head>
<body [class.fixed]="isFixed">
<my-app>Loading...</my-app>
</body>
</html>
我的应用组件看起来像
import {Component} from 'angular2/core';
import {CORE_DIRECTIVES} from 'angular2/common';
import {RouteConfig, ROUTER_DIRECTIVES, Router, Location} from 'angular2/router';
import {About} from './components/about/about';
import {Test} from './components/test/test';
@Component({
selector: 'my-app',
providers: [],
templateUrl: '/views/my-app.html',
directives: [ROUTER_DIRECTIVES, CORE_DIRECTIVES],
pipes: []
})
@RouteConfig([
{path: '/about', name: 'About', component: About, useAsDefault: true},
{path: '/test', name: 'Test', component: Test}
])
export class MyApp {
router: Router;
location: Location;
constructor(router: Router, location: Location) {
this.router = router;
this.location = location;
}
}
【问题讨论】:
-
您是否尝试过仅使用
"body"作为应用程序组件的选择器? -
谢谢,刚试了没成功。应用程序仍然有效,但我认为它只在
body内部引导,而没有body本身。如果我将选择器更改为html- 它会用组件模板替换我的头部和身体..
标签: javascript angular