2016-04-04 8 views
0

Я пытаюсь запустить проект с помощью Angular2 и ES6, но у меня есть проблема с доступом к моим данным.Не удается получить доступ к значениям Angular2

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 [email protected]:19] 
+0

был просто из-за ошибки – Ajouve

ответ

0

Кажется, работает хорошо для меня ->Plunker example

Я просто должен был удалить кавычку из

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

удалить эту строку из HTML, он должен начать работать,

<!-- conditionally display `yourName` --> 
Смежные вопросы