2016-01-20 42 views
0
angular.module('app', []).controller('MessagesCtrl', function() { 

$scope.self.list = [ 
{text: 'Hello, World!'}, 
{text: 'This is a message'}, 
{text: 'And this is another message'} 
]; 

self.clear = function() { 
$scope.self.list = []; 
}; 
}); 

这是一个以角度编写的控制器。我如何使用EM6将其转换为角度2。如何使用EM6将angularJS版本1.X控制器转换为角度2.X ngupgrade

+0

任何一个可以共享教程升级角的1.x到使用EM6或EM5 –

+0

角2.x中没有“控制器”在角2.你要么通过ngUpgrade或改写升级您的指令或组件他们在Angular 2.让我知道你在找什么,我应该能够给你一些例子。 – sdfacre

+0

打字稿“从'angular2/upgrade'导入{UpgradeAdapter};”用于导入UpgradeAdapter.I想知道如何使用EM6或EM 5 –

回答

0

据我所知,目前还没有很多升级教程,但是很少有。

https://angular.io/docs/ts/latest/guide/upgrade.html

http://blog.thoughtram.io/angular/2015/10/24/upgrading-apps-to-angular-2-using-ngupgrade.html

那么,让我告诉你基本angular2应用。

在角1.x中我们主要模块用来初始化这样

angular.module('app', []) 

但在angular2我们的主要成分由这样的bootstraped文件启动。

import {bootstrap} from 'angular2/platform/browser'; 
import {App} from './app'; 

bootstrap(App,['here global level dependenices....']); 

这里的应用程序是whihc在此引导文件导入我们的主要成分。因此引导文件是我们的应用程序的入口点。和 如果我们想要做一些编码的东西,就像我们在angular1.x控制器中工作一样,我们在类文件(typescript class) 中做同样的工作,在这里我发布了一个像这样的基本示例。

import {Component, View} from 'angular2/core'; 

@Component({ 
    selector: 'app', 
    templateUrl: "src/app.html", 
    styleUrls: ['src/app.css'], 
    directives: [ directives list here....], 
}) 

export class App 
{ 
    // stuff you want to do here 
} 

首先,我们必须从systemjs束像我们进口组件和视图中从angular2 /芯本实施例中导入angular2束。 有很多可用于angular2的导入。你可以check out herehere

+0

在这里升级使用类型脚本完成。是否有任何教程在EM6 –

+0

https://angular.io/docs/js/latest/guide/在这里检查...不知道es6抱歉。 –