Angular 2:多个html代码行(模板)不在浏览器中呈现

时间:2016-12-20 12:30:57

标签: javascript angular typescript

我的app.component.html文件中有一段HTML代码作为我的模板。此代码拒绝在浏览器上呈现。但是当我用较短的代码行替换该文件的整个内容时,浏览器会显示该代码。通过较短的代码行,我的意思是像 <h1>Hello there</h1> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,</p>

以下是我的代码:app.component.html

<div class="locator">
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <header class="inner-page-header landing-page-header">
          <span>Welcome to</span>
          <h1 class="start">Food</h1>
          <p>Daily new menus of breakfast, lunch, evening snacks and dinner; prepared by expert chefs.</p>
          <p>
          </p>
        </header>
        <div class="holder landing-page-form">
          <form accept-charset="UTF-8" action="/localities/set_locality"
                class="location-form col-xs-12 col-sm-6 col-sm-offset-3" data-remote="true" id="zip_form"
                method="get">
            <div style="display:none">
              <input name="utf8" type="hidden" value="✓">
            </div>
            <p>SELECT LOCATION </p>
            <hr class="small-line">
            <div id="locationField">
              <input class="form-control" id="autocomplete" placeholder="Enter your address"
                     onFocus="geolocate()" type="text"></input>
            </div>
            <div class=" text-center">
              <button id="singlebutton" name="findfood" class="btn btn-lg btn-space btn-primary">Find food</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {

}

index.html

......
  <div class="page-content">

    <app-root>Loading...</app-root>

  </div>
.......

我看到的所有输出都是:Loading

我错过了什么?

2 个答案:

答案 0 :(得分:1)

<input class="form-control" id="autocomplete" placeholder="Enter your address"
                 onFocus="geolocate()" type="text"></input> <!-- error here --> 

删除</input>

之后它会呈现,至少对我而言。

EDIT。检查浏览器中的开发工具,它会告诉错误在哪里! enter image description here

答案 1 :(得分:0)

你错过了在课堂上定义这个功能。在课堂上定义 geolocate 方法。它应该解决你的问题

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
    geolocate() {
    }
}