Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何使用@Angular/upgrade在Angular 1应用程序中使用Angular 2组件_Angularjs_Angular_Angular Upgrade_Angular Hybrid - Fatal编程技术网

Angularjs 如何使用@Angular/upgrade在Angular 1应用程序中使用Angular 2组件

Angularjs 如何使用@Angular/upgrade在Angular 1应用程序中使用Angular 2组件,angularjs,angular,angular-upgrade,angular-hybrid,Angularjs,Angular,Angular Upgrade,Angular Hybrid,这个问题可能重复,但我已经尝试了所有可能的选择 我正在尝试使用@Angular/upgrade在Angular 1应用程序中使用我的Angular 2组件 angular2文件:- app/components/hello中的简单hello组件 您好,component.ts import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-hello', templateUrl: './hell

这个问题可能重复,但我已经尝试了所有可能的选择

我正在尝试使用@Angular/upgrade在Angular 1应用程序中使用我的Angular 2组件

angular2文件:-

app/components/hello中的简单hello组件

您好,component.ts

import { Component, OnInit } from '@angular/core';
@Component({
  selector: 'app-hello',
  templateUrl: './hello.component.html',
  styleUrls: ['./hello.component.scss']
})
export class HelloComponent implements OnInit {

  constructor() { 
  }

  ngOnInit() {
  }

}
hello.component.html

<p>
  hello works!
</p>
在我的Angular 1应用程序中:- app.ts(根文件)

Angular 1的index.html(我添加了base href和root,这是Angular的默认组件,应用程序根组件在我的Angular 1应用程序中正确呈现)


提前谢谢。

不能在同一混合中使用降级模块()和升级模块 应用用一个或另一个


这意味着您只能在引导NG1时使用降级模块

我使用的是
gradecomponent
而不是
grademodule()
。您是对的(我的错)。我可以看出,您既可以手动引导,也可以自动引导。尝试删除引导:[AppComponent],我已删除
此.upgrade.bootstrap(document.body,['usr'])即使不起作用,但当我在根组件中添加hello组件时,它仍能正确呈现。您无法删除此。升级。引导(document.body,['usr']);因为这是引导ng1的功能,这是另一个需要删除的功能
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { UpgradeModule } from '@angular/upgrade/static';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HelloComponent } from './components/hello/hello.component';

@NgModule({
  declarations: [
    AppComponent,
    HelloComponent
  ],
  imports: [
    BrowserModule,
    UpgradeModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent],
  entryComponents: [
    HelloComponent
  ]
})
export class AppModule { 
  constructor(private upgrade: UpgradeModule) { }
  ngDoBootstrap() {
    this.upgrade.bootstrap(document.body, ['usr']);
  }
}

platformBrowserDynamic().bootstrapModule(AppModule);
import { HelloComponent } from '../angular/src/app/components/hello/hello.component';
import { downgradeComponent } from './node_modules/@angular/upgrade/static/static'

let moduleList = ['ngCookies', 'ngSanitize','$rootScope', '$locationProvider '];
angular.bootstrap(document.body, ['usr']);

let app: any = angular.module('usr', moduleList)
.directive(
    'appHello',
    downgradeComponent({ component: HelloComponent })
  );
<base href="/">
<app-root></app-root>
<app-hello></app-hello>