简体   繁体   English

Angular2根组件与主体选择器

[英]Angular2 Root component with body selector

I have an app using angularjs, and i want to start rewriting this app to Angular2. 我有一个使用angularjs的应用程序,我想开始将此应用程序重写为Angular2。 Original app is unfortunately mix of Asp.Net MVC when body was as as ng-app. 不幸的是原始应用程序混合了Asp.Net MVC,当身体像ng-app一样。

I want to do the similar approach in Angular2 to set AppComponent selector to body. 我想在Angular2中使用类似的方法将AppComponent选择器设置为body。 So then i will be able to take step by step rewriting old app to new components but. 那么我将能够一步一步地将旧应用程序重写为新组件但是。

My problem is that template is required inside of component. 我的问题是组件内部需要模板。 Is this possible to be without template since html will be printed from server? 这可能是没有模板,因为HTML将从服务器打印?

Currently it works like that. 目前它是这样的。 When user hits page Server returns html 当用户点击页面时,服务器返回html

<html>
<body ng-app="flymark">

Here could be any angular directive or other controolers

</body>
</html>

This is possible If I understand correctly , It is not always the case that you have to use template inside component only it depends on your preference and needs : 这是可能的如果我理解正确,并非总是必须在组件内部使用模板,这取决于您的偏好和需求:

You have two options to use template: 您有两种方法可以使用模板:

  1. Template 模板
  2. TemplateURL : TemplateURL:

    templateUrl: ' https://test.html ',
    styleUrls: ['https:/test.css']

You may use template URL and pass your servers URL to the template URL this should work perfectly fine but you must do changes on your template even though it is in server so as to interact with your component or it wont respond the way you want it to ... 您可以使用模板URL并将您的服务器URL传递给模板URL,这应该完全正常,但您必须对模板进行更改,即使它在服务器中以便与您的组件交互,或者它不会以您希望的方式响应...

You should divide your html into several other components as per your needs providing the URL. 您应该根据提供URL的需要将html分成几个其他组件。 This will enable you to target whatever portion of template you want. 这将使您能够定位所需模板的任何部分。

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

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