繁体   English   中英

无法访问值Angular2

[英]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]

似乎对我来说工作正常-> Plunker示例

我只需要删除反引号即可

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

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

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

暂无
暂无

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

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