Last active
September 19, 2016 07:36
-
-
Save bartoszbobin/11a7b4765a24f06e80195f4b3a7d3def to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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