Skip to content

Instantly share code, notes, and snippets.

@bartoszbobin
Last active September 19, 2016 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartoszbobin/11a7b4765a24f06e80195f4b3a7d3def to your computer and use it in GitHub Desktop.
Save bartoszbobin/11a7b4765a24f06e80195f4b3a7d3def to your computer and use it in GitHub Desktop.
'use strict';
// file: route.cfg.ts
class RouteConfig
{
public static $inject = ['$stateProvider'];
public constructor($stateProvider : angular.ui.IStateProvider){
$stateProvider
.state("home", {
url: "/",
controller: "MainCtrl", // 2nd place
template: '<p></p>'
})
.state('map', { // 1st place
url: '/map',
controller: "MapCtrl"
});
}
}
// file: bobin.svc.ts
class BobinService
{
public static $inject = ['$rootScope'];
public constructor(private $rootScope : angular.IRootScopeService){}
public emit() {
this.$rootScope.$emit("myEmitActionName"); // 4th place
}
}
// file: main.ctrl.ts
class MainCtrl
{
public static $inject = ['$state', 'BobinService']; // 3rd place
public constructor(private $state : angular.ui.IStateService,
private bobinService : BobinService){}
public edit() {
this.$state.go('map'); // 1st place
}
}
// file: map.ctrl.ts
class MapCtrl
{
public static $inject = ['$scope'];
public constructor(private $scope : angular.IScope) {
this.$scope.$on('myEmitActionName', () => this.listen()); // 4th place
}
public listen() {
// do something
}
}
// file: app.ts
angular.module('bobin', ['ui.router'])
.controller('MainCtrl', MainCtrl) // 2nd place
.controller('MapCtrl', MapCtrl)
.service('BobinService', BobinService) // 3rd place
.config(RouteConfig);
'use strict';
replaceable EMIT_ACTION = "myEmitActionName";
replaceable ROUTING = {
HOME: 'home',
MAP: 'map'
};
// file: route.cfg.ts
class RouteConfig
{
public static $inject = ['$stateProvider'];
public constructor($stateProvider : angular.ui.IStateProvider){
$stateProvider
.state(ROUTING.HOME, {
url: "/",
controller: MainCtrl.NAME, // 2nd place
template: '<p></p>'
})
.state(ROUTING.MAP, { // 1st place
url: '/map',
controller: MapCtrl.NAME
});
}
}
// file: bobin.svc.ts
class BobinService
{
public static $inject = ['$rootScope'];
public replaceable NAME = 'BobinService';
public constructor(private $rootScope : angular.IRootScopeService){}
public emit() {
this.$rootScope.$emit(EMIT_ACTION); // 4th place
}
}
// file: main.ctrl.ts
class MainCtrl
{
public static $inject = ['$state', BobinService.NAME]; // 3rd place
public replacable static NAME = 'MainCtrl';
public constructor(private $state : angular.ui.IStateService,
private bobinService : BobinService){}
public edit() {
this.$state.go(ROUTING.MAP); // 1st place
}
}
// file: map.ctrl.ts
class MapCtrl
{
public static $inject = ['$scope'];
public replacable static NAME = 'MapCtrl';
public constructor(private $scope : angular.IScope) {
this.$scope.$on(EMIT_ACTION, () => this.listen()); // 4th place
}
public listen() {
// do something
}
}
// file: app.ts
angular.module('bobin', ['ui.router'])
.controller(MainCtrl.NAME, MainCtrl) // 2nd place
.controller(MapCtrl.NAME, MapCtrl)
.service(BobinService.NAME, BobinService) // 3rd place
.config(RouteConfig);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment