【问题标题】:Can't access values Angular2无法访问值Angular2
【发布时间】:2016-04-04 12:23:22
【问题描述】:

我正在尝试使用 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]

【问题讨论】:

  • 只是因为丑陋的问题

标签: javascript angular ecmascript-6


【解决方案1】:

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

我只需要从

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-02
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多