Created by Tony Gemoll
Because of this...
myApp.controller('MyController', ['$scope', function($scope) {
//Thousands of lines of code
}]);
angular.module('app',
[
uiRouter,
home.name,
widget.name
])
.directive('app', appDirective);
bootstrap(App, [
HTTP_PROVIDERS,
ROUTER_PROVIDERS,
APP_ROUTER_PROVIDERS
]);
Small, possibly reusable, piece of an application's functionality.
angular.module('widget',
[]) //dependencies
.config(['', //string based injection
() => { //module configurations }
])
.directive('widget', widgetDirective);
export const widgetDirective = ()=> {
return {
``,
controller,
controllerAs: 'widget',
...
};
};
class WidgetController {
constructor(foo) {
this.foo = foo;
}
widgetMethod(str) {
this.foo.bar(str);
}
}
WidgetController.$inject = ['Foo']; //string based injection.
export {WidgetController};
@Component({
selector: 'widget',
template: ``,
directives: [],
providers: [Foo]
})
export class WidgetComponent {
constructor(private foo: Foo) {
}
widgetMethod(str: string) {
this.foo.bar(str);
}
}
https://angular.io/docs/ts/latest/cookbook/a1-a2-quick-reference.html
input value: {{vm.inputValue | uppercase}}
input value: {{inputValue | uppercase}}
Where the logic happens
myModule.service('widgetService', WidgetService);
or
myModule.factory('widgetFactory', WidgetService);
or
myModule.provider('widgetProvider', WidgetService);
class WidgetService {
constructor($http) {
this.$http = $http;
}
getWidget() {
//return some widgets
}
}
WidgetService.$inject = ['$http']; //string based injection
export {WidgetService};
@Injectable()
export class WidgetService {
constructor(private http: Http){
}
getWidget() {
}
}
Assumes use of ui-router
export const peopleSearch = angular.module('widget',
[uiRouter])
.config(['$stateProvider',
($stateProvider) => {
$stateProvider
.state('widget', {
url: '/widget/',
template: ' '
})
.state('widgetWithParameter', {
url: '/widget/:aParameter',
template: ' '
});
}])
export const routes: RouterConfig = [
{ path: 'widget', component: WidgetComponent },
{ path: 'widget/:aParameter', component: WidgetComponent },
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];
import { APP_ROUTER_PROVIDERS } from './app.routes';
bootstrap(AppComponent, [
APP_ROUTER_PROVIDERS
])
Widget!
Widget with foo!
Widget!
Widget with foo!
https://github.com/Microsoft/TypeScript-Sublime-Plugin/blob/master/screenshots/
https://github.com/Microsoft/TypeScript-Sublime-Plugin/blob/master/screenshots/
var keyup = Rx.Observable.fromEvent($input, 'keyup')
.map(function (e) {
return e.target.value;
})
.filter(function (text) {
return text.length > 2;
})
.debounce(750)
.distinctUntilChanged()
.flatMapLatest(searchWikipedia) //ajax call to get data
.subscribe((data) => { //put in DOM here } );
https://github.com/Reactive-Extensions/RxJS/blob/master/examples/autocomplete/autocomplete.js