无法访问Angular2的值

时间:2016-04-04 12:23:22

标签: javascript angular ecmascript-6

我正在尝试使用Angular2和ES6启动项目,但我在尝试访问我的数据时遇到了问题。

index.js

import {zoneJs} from 'zone.js'
import {reflectMetadata} from 'reflect-metadata'
import {bootstrap}  from 'angular2/platform/browser';
import {HelloWorld} from './hello_world';
bootstrap(HelloWorld);

hello_world.js

import {Component} from 'angular2/core';

@Component({
  // Declare the tag name in index.html to where the component attaches
  selector: 'hello-world',
  // Location of the template for this component
  templateUrl: 'dist/template/hello_world.html'
})

export class HelloWorld {
  yourName = ''
}

hello_world.hlml

<label>Name:</label>
<!-- data-bind to the input element; store value in yourName -->
<input type="text" [(ngModel)]="yourName" placeholder="Enter a name here">
<hr>
<!-- conditionally display `yourName` -->
<h1 [hidden]="!yourName">Hello {{yourName}}!</h1>

我的网页上有模板,但我有以下错误

script.js:17 EXCEPTION: No value accessor for '' in [yourNames in s@2:19]

2 个答案:

答案 0 :(得分:0)

似乎对我有用 - &gt; Plunker example

我只需要从

中删除反引号
<!-- conditionally display `yourName` -->

答案 1 :(得分:0)

从HTML中删除此行,它应该开始工作,

<!-- conditionally display `yourName` -->