我是 Angular 新手,这是第一次体验。
我的最终目标是在 Angular 2 中使用以下组件 http://mb21.github.io/JSONedit/
我了解一些 javascript,并且尝试在 Angular 2 项目中使用 Angular 1 库。
通过我的搜索,我找到了这个主题: Using Angular 1 libraries in Angular 2?
但正如答案所说“一般来说,不会”,我假设可以在 Angular 2 中使用 Angular 1 的某些组件。因此,我尝试使以下代码在 Angular 2 中运行作为测试:
Translation-module.component.html
<select ng-model="selectedName" ng-options="x for x in names">
<option>teste</option>
</select>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.names = ["Emil", "Tobias", "Linus"];
});
</script>
translation-module.component.ts
import { CUSTOM_ELEMENTS_SCHEMA , Component, OnInit, ViewChild } from '@angular/core';
import { angular } from 'angular';
ngAfterViewChecked() {
// $("#content").load("http://www.google.com");
var app = angular.module('myApp', []);
app.controller('myCtrl', function() {
this.names = ["Emil", "Tobias", "Linus"];
});
}
但这似乎不起作用。我从 Angular1 和 Angular 2 导入 .js。有人可以解释一下为什么这不起作用吗?
提前谢谢
最佳答案
Angular 开发团队考虑了同样的问题,并引入了升级模块来帮助无缝升级您的应用程序。您可以引用以下链接:- https://angular-2-training-book.rangle.io/handout/migrate/ng-upgrade/ https://angular.io/guide/upgrade
如果您对 ng-upgrade 有任何具体问题,请询问。
关于javascript - 同时使用 Angular 1 和 Angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46100796/