同时使用角度1和角度2

时间:2017-09-07 16:02:41

标签: javascript angularjs angular

我是棱角分明的新人,这是第一次体验。

我的最终目标是在角度2中使用以下组件 http://mb21.github.io/JSONedit/

我知道一些javascript,我试图在Angular 2项目中使用Angular 1库。

根据我的搜索,我找到了这个主题: Using Angular 1 libraries in Angular 2?

但正如答案所述“一般情况下,没有”我假设可以在角度2中使用角度1的某些组件。所以我试图使下面的代码以角度2运行作为测试:

翻译-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>

翻译-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。有人可以解释一下为什么这不起作用吗?

提前谢谢

1 个答案:

答案 0 :(得分:0)

Angular开发团队已经考虑过同样的问题并引入了升级模块,以帮助无缝升级您的应用程序。您可以参考以下链接: - https://angular-2-training-book.rangle.io/handout/migrate/ng-upgrade/ https://angular.io/guide/upgrade

如果您对ng-upgrade有任何疑问,请询问。

相关问题