简体   繁体   English

属性到 AppComponent 返回空值 Angular 2

[英]Property into AppComponent returns empty value Angular 2

I'm trying the heros tutorial from the angular 2 official site:我正在尝试 angular 2 官方网站上的英雄教程:

https://angular.io/docs/ts/latest/tutorial/toh-pt1.html https://angular.io/docs/ts/latest/tutorial/toh-pt1.html

But I can't retrieve the values for AppComponent, it always returns an empty value.但是我无法检索 AppComponent 的值,它总是返回一个空值。

Here the code of app.component.ts这里是 app.component.ts 的代码

import { Component } from '@angular/core';
@Component({
  selector: 'my-app',
  template: '<h1>Titulo: {{titulo}}</h1>'
})
export class AppComponent { 
    titulo: 'Tour de heroes';
}

When I save the changes and refresh the page I only get: Titulo:当我保存更改并刷新页面时,我只会得到:标题:

It should be titulo = 'Tour de heroes' , not titulo: 'Tour de heroes' .它应该是titulo = 'Tour de heroes' titulo: 'Tour de heroes' titulo = 'Tour de heroes' ,而不是titulo: 'Tour de heroes'

: is used to assign type to variable, = is used to assign value to variable. :用来给变量赋值, =用来给变量赋值。 Example:例子:

titulo: string = 'Tour de heroes'

The code above declares variable titulo of type string and assigns value Tour de heroes to it.上面的代码声明变量titulo类型的string和受让人值Tour de heroes给它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM