Я понизил версию компонента, написанного на Angular2 + Typescript. Теперь я хочу использовать его в простом приложении angular 1, но файл js, скомпилированный из Typescript, использует «импорт», и я получаю из браузера, что он не поддерживается. Что я пропустил?
Это простой компонент angular 2:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'hello-world',
template: `
<p>
hello from angular 2!
</p>
`,
styles: []
})
export class HelloWorldComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
import * as angular from 'angular';
import { downgradeComponent } from '@angular/upgrade/static';
angular.module('dannyApp', [])
.directive(
'helloWorld',
downgradeComponent({component: HelloWorldComponent}) as angular.IDirectiveFactory
);
Это простое приложение angular1, использующее этот компонент angular 2 выше:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script src="dist\out-tsc\app\hello-world\hello-world.component.js"></script>
<script>
angular.module('app', [])
.controller('FrameController', ['$injector', function($injector) {
var vm = this;
vm.message = 'Hello from angular 1';
}]);
</script>
<title>Title</title>
</head>
<body ng-app="app">
<div id="body">
<div ng-controller="FrameController as vm">
{{vm.message}}
</div>
<!-- the angular 2 componenet -->
<hello-world></hello-world>
</div>
</body>
</html>
Ошибка браузера: Uncaught SyntaxError: Неожиданный импорт токена в строке:
import { Component } from '@angular/core';