如果private
在组件类上声明了变量,我是否应该能够在该组件的模板中访问它?
@Component({
selector: 'my-app',
template: `
<div>
<h2>{{title}}</h2>
<h2>Hello {{userName}}</h2> // I am getting this name
</div>
`,
})
export class App {
public title = 'Angular 2';
private userName = "Test Name"; //declared as private
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试按照本指南https://angular.io/docs/ts/latest/guide/ngmodule.html引导我的Angular 2 RC5应用程序. 下面是我的代码
import { AppModuleNgFactory } from './app.module.ngfactory';
import {platformBrowser} from "@angular/platform-browser";
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试编译打字稿代码时,我收到以下错误
app\main.ts(1,36):错误TS2307:找不到模块'./app.module.ngfactory'.
如何生成app.module.ngfactory文件?我应该使用哪种工具?
在我使用的Angular 2/Ionic 2(final/rc0)项目中的组件中:
protected contentTarget: ViewContainerRef;
ngOnInit() {
this.contentTarget.createComponent(componentFactory);
}
Run Code Online (Sandbox Code Playgroud)
AoT编译器说:
Error at ....: Property 'contentTarget' is protected and only accessible within class 'IncludeTemplateComponent' and its subclasses.
Run Code Online (Sandbox Code Playgroud)
变量(属性)不会在整个项目中的任何其他位置使用.
那么......任何人都可以对此有所了解,是createComponent工厂将contentTarget变量传递给它的子节点,或者为什么编译器不喜欢这里受保护?现在所有Angular2中的受保护变量都是"被禁止的"吗?