Lorem ipsum dolor sit amet, consectetur ...
Yaniv Efraim
Wix.com
I am a Javascript engineer @Wix
Passionate about Javascript and Angular. Hacking on migrating to Angular 2.0 stuff on the last few months.
(Write everything from scratch)
import {Component, View, EventEmitter} from 'angular2/core';
@Component({
selector: 'font-size-component',
inputs: ['fontSize'],
outputs: ['fontSizeChange']
})
@View({
template: ``,
directives: [FORM_DIRECTIVES]
})
export class FontSizeComponent {
fontSize: string;
fontSizeChange: EventEmitter = new EventEmitter();
modelChanged($event) {
this.fontSizeChange.emit($event);
}
}
Items
-
{{item.text}}
function MainController() {
var ctrl = this;
ctrl.items = [{title: 'title 1', text: 'item 1'}, {...}];
ctrl.deleteItem = function(item) {
var idx = ctrl.items.indexOf(item);
if (idx >= 0) {
ctrl.items.splice(idx, 1);
}
};
}
Items
module.directive('itemList', function() {
return {
scope: {},
controller: function() {
var ctrl = this;
ctrl.deleteItem = function(item) {
var idx = ctrl.items.indexOf(item);
if (idx >= 0) {
ctrl.items.splice(idx, 1);
}
};
},
controllerAs: 'itemListCtrl',
bindToController: {
items: '='
},
templateUrl: 'item-list.html'
};
});
(our component is mutating data it doesn't own!)
ctrl.deleteItem = function(item) {
var idx = ctrl.items.indexOf(item);
if (idx >= 0) {
ctrl.items.splice(idx, 1);
}
};
module.directive('itemList', function() {
return {
scope: {},
controller: function() {
var ctrl = this;
ctrl.deleteItem = function(item) {
ctrl.onDelete({item: item});
};
},
controllerAs: 'itemListCtrl',
bindToController: {
items: '=',
onDelete: '&'
},
templateUrl: 'item-list.html'
};
});
Items
module.directive('itemList', function() {
return {
scope: {},
controller: function() {
var ctrl = this;
ctrl.deleteItem = function(item) {
ctrl.onDelete({item: item});
};
},
controllerAs: 'itemListCtrl',
bindToController: {
items: '=', //input
onDelete: '&' //output
},
templateUrl: 'item-list.html'
};
});
Lorem ipsum dolor sit amet, consectetur ...
directive('fontSizeComponent', function() {
return {
template: '',
scope: {},
bindToController: {
fontSize: "@",
fontSizeChanged: "&"
},
controllerAs: 'ctrl',
controller: function() {
var that = this;
this.modelChanged = function() {
that.fontSizeChanged({fontSize: that.fontSize});
};
}
};
});
//TypeScript
var bar: string;
var func: Function;
//Compiled to
var bar;
var func;
import angular from 'angular';
class FontSizeComponent {
/* @ngInject */
constructor() {
}
modelChanged() {
this.fontSizeChanged({fontSize: this.fontSize});
}
}
export default angular.module('themeCreatorFontSizeComponentModule', [])
.directive('fontSizeComponent', function() {
return {
template: ``,
scope: {
fontSize: "@",
fontSizeChanged: "&"
},
bindToController: true,
controllerAs: 'ctrl',
controller: FontSizeComponent
};
});
import angular from 'angular';
class FontSizeComponent {
fontSize: string; //font size is of type string
fontSizeChanged: Function; //fontSizeChanged is of type Function
/* @ngInject */
constructor() {
}
modelChanged() {
this.fontSizeChanged({fontSize: this.fontSize});
}
}
export default angular.module('themeCreatorFontSizeComponentModule', [])
.directive('fontSizeComponent', function() {
return {
template: ``,
scope: {
fontSize: "@",
fontSizeChanged: "&"
},
bindToController: true,
controllerAs: 'ctrl',
controller: FontSizeComponent
};
});
import {Component, View, EventEmitter} from 'angular2/core';
@Component({
selector: 'font-size-component',
inputs: ['fontSize'],
outputs: ['fontSizeChange']
})
@View({
template: ``
})
export class FontSizeComponent {
fontSize: string;
fontSizeChange: EventEmitter = new EventEmitter();
modelChanged($event) {
this.fontSizeChange.emit($event);
}
}
app.controller('AppController', function ($router) {
$router.config([
{
path: '/welcome',
component: 'welcome'
}
]);
});