简体   繁体   English

角度2:浏览器中未呈现多行html代码行(模板)

[英]Angular 2: Multiple html lines of code(template) not rendering in browser

I have a block of HTML code as my template in my app.component.html file. 我的app.component.html文件中有一块HTML代码作为模板。 This code refused to render on the browser. 该代码拒绝在浏览器中呈现。 But when I replace the entire content of that file with shorter lines of code, the browser displays that. 但是,当我用较短的代码行替换该文件的全部内容时,浏览器就会显示出来。 By shorter lines of code, I mean something like 用较短的代码行,我的意思是
<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> <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> . <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><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>

Below is my code: app.component.html 下面是我的代码: 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 : 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 : index.html

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

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

  </div>
.......

All I see as output is: Loading 我看到的输出是: Loading

What am I missing? 我想念什么?

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

Remove </input> 删除</input>

After that it renders, at least for me. 之后,至少对我而言。

EDIT. 编辑。 Check the dev tools in browser, it tells where the error is! 在浏览器中检查开发工具,它会告诉您错误在哪里! 在此处输入图片说明

you missed to define the function in class. 您错过了在课堂上定义函数的机会。 Define geolocate method in class. 在类中定义geolocate方法。 it should fix your problem 它应该解决您的问题

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM