在Angular 7中使用AngularJS框架的方法如下:
npm install angular --save
import * as angular from 'angular';
@NgModule({
imports: [
...
],
declarations: [
...
],
providers: [
...
],
})
export class AppModule {
constructor(private upgrade: UpgradeModule) {}
ngDoBootstrap() {
this.upgrade.bootstrap(document.body, ['myApp'], { strictDi: true });
}
}
angular.module('myApp', []);
import * as angular from 'angular';
angular.module('myApp')
.controller('myController', function($scope) {
$scope.message = 'Hello AngularJS!';
});
{{ message }}
import { UpgradeModule } from '@angular/upgrade/static';
@NgModule({
imports: [
...
UpgradeModule
],
declarations: [
...
],
providers: [
...
],
})
export class AppModule {
constructor(private upgrade: UpgradeModule) {}
ngDoBootstrap() {
this.upgrade.bootstrap(document.body, ['myApp'], { strictDi: true });
}
}
这样,你就可以在Angular 7中使用AngularJS框架了。在HTML模板中,你可以使用ng-controller指令来绑定AngularJS控制器,以及在控制器中使用$scope对象来管理数据和逻辑。