首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法访问值Angular2

无法访问值Angular2
EN

Stack Overflow用户
提问于 2016-04-04 20:23:22
回答 2查看 43关注 0票数 0

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

index.js

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
<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>

该模板在我的网页中重现,但我有以下错误

代码语言:javascript
复制
script.js:17 EXCEPTION: No value accessor for '' in [yourNames in s@2:19]
EN

回答 2

Stack Overflow用户

发布于 2016-04-04 20:28:28

看起来很适合我-> Plunker example

我只需要去掉后面的

代码语言:javascript
复制
<!-- conditionally display `yourName` -->
票数 0
EN

Stack Overflow用户

发布于 2016-04-04 20:28:44

从HTML中删除这一行,它应该会开始工作,

代码语言:javascript
复制
<!-- conditionally display `yourName` -->
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36402553

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档