简体   繁体   English

HTML的Angular6调用组件

[英]Angular6 Calling Component From HTML

Giving Angular6 a try. 尝试一下Angular6。 In my Angular1 app, I bind scopes to html like so: 在我的Angular1应用程序中,我将范围绑定到html,如下所示:

<div ng-controller="MyCtrl">

</div>

Now in Angular6, which is component based, there is: 现在基于组件的Angular6中有:

@Component({
  selector: 'app-side-bar-toggle',
  templateUrl: './side-bar-toggle.component.html',
  styleUrls: ['./side-bar-toggle.component.css']
})

Is there a way to: 有没有办法:

  1. First output html to a page via Python, PHP, etc 首先通过Python,PHP等将html输出到页面

  2. Have a component bind to a section of that page that was outputted? 是否有组件绑定到该页面的已输出部分?

From Angular2 onwards, the structure of an Angular application has totally changed. 从Angular2开始,Angular应用程序的结构已完全改变。

There is a root bootstrap module and in it you have a bootstrap component Once your application runs, the root module take control and the bootstrap component is launched. 有一个根引导程序模块 ,其中有一个引导程序组件。一旦您的应用程序运行,该根模块将控制并启动引导程序组件。 HTML rendering shall be the responsibility of Angular framework now. 现在,HTML渲染将成为Angular框架的责任。 Server side languages like PHP, Python, C# shall work as providers of REST services that Angular framework will interact with. 服务器端语言(如PHP,Python,C#)应作为Angular框架将与之交互的REST服务的提供者。

So to answer your questions 所以回答你的问题

1.) Angular Components could display HTML based on a call to a RESTful Server Side Service and using *ngIf, *ngFor etc to render data in HTML format as desired. 1.)Angular Components可以基于对RESTful服务器端服务的调用显示HTML,并根据需要使用* ngIf,* ngFor等以HTML格式呈现数据。

2.) A parent component can combine multiple components in its template using the component-selector eg 2.)父组件可以使用组件选择器在其模板中组合多个组件

<my-first-component></my-first-component>
<p>some html</p>
<my-second-component [InputProperty]="Some Value"></my-second-component>

etc.. 等等..

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

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