2016-05-21 13 views
1

機能するコンポーネントプロパティの補間を取得できません。入力した場合は{{1+1}}となりますが、そうではありません。私は単に{{title}}を表示させようとしていますが、私は2つの場所(appとNutriFormコンポーネント)で宣言しましたが、何も動作しません。角度2の補間が機能しない

これらは関連するファイルです。

app.component.ts

import { Component } from '@angular/core'; 
import {NutriFromComponent} from './NutriForm.component' 

@Component({ 
    selector: 'my-app', 
    directives: [NutriFromComponent], 
    template: '<NutriForm></NutriForm>' 
}) 
export class AppComponent { 
    title = "hello"; 
} 

plain.html

<html> 
    <head> 
     <title>Angular 2 QuickStart</title> 
     <meta charset="UTF-8"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <link href="../public/stylesheets/style.css" rel="stylesheet" /> 
     <!-- 1. Load libraries --> 
     <!-- Polyfill(s) for older browsers --> 
     <script src="node_modules/core-js/client/shim.min.js"></script> 
     <script src="node_modules/zone.js/dist/zone.js"></script> 
     <script src="node_modules/reflect-metadata/Reflect.js"></script> 
     <script src="node_modules/systemjs/dist/system.src.js"></script> 
     <!-- 2. Configure SystemJS --> 
     <script src="systemjs.config.js"></script> 
     <script> 
      System.import('app').catch(function(err){ console.error(err); }); 
     </script> 
    </head> 
    <!-- 3. Display the application --> 
    <body> 
     <my-app>Loading...</my-app> 
    </body> 
</html> 

NutriForm.component.ts

import {Component} from '@angular/core'; 
import {Control , FormBuilder , Validators , NgForm} from '@angular/common'; 
import {ControlGroup} from '@angular/common'; 
import {NutriModel} from '../Models/NutriModel.ts'; 

@Component({ 
    selector: 'NutriForm', 
    templateUrl: 'views/NutriForm.component.html' 
}) 
export class NutriFromComponent { 

    title: string; 

    constructor() { 
     this.title = 'Tour of Heroes'; 
    } 
} 

NutriForm.component.html

<h2> {{title}}</h2> 

<table> 
    <tr> 
     <td></td> 
     <td>Your Value</td> 
     <td>Recommended</td> 
     <td>Average</td> 
    </tr> 
    <tr> 
     <!--<td><input type="text" required [(ngModel)]="model.sex" ngControl="sex" /></td>--> 
     <td>Your Value</td> 
     <td>Recommended</td> 
     <td>Average</td> 
    </tr> 

</table> 

<button type="submit" class="btn btn-default">Submit</button> 
+3

コードがよさそうだ働く必要があります。さらなる調査のためにそれをプランナーに入れてください。そうでなければ、誰が何が間違っているかを知ることはできません。 Plunkerの例: '{{title}}'の出力:https://angular.io/resources/live-examples/toh-1/ts/plnkr.html – tibbus

+0

? –

答えて

1

代わり

export class NutriFromComponent { 

    title: string; 

    constructor() { 
     this.title = 'Tour of Heroes'; 
    } 
} 

export class NutriFromComponent { 

    title = 'Tour of Heroes'; 

} 

を適用することが

関連する問題