[英]Can't access values Angular2
我正在嘗試使用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>
該模板在我的網頁上顯示為rendre,但是出現以下錯誤
script.js:17 EXCEPTION: No value accessor for '' in [yourNames in s@2:19]
從HTML刪除此行,它應該開始工作,
<!-- conditionally display `yourName` -->
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.