Skip to content

Instantly share code, notes, and snippets.

@Qvatra
Created December 1, 2014 15:41
Show Gist options
  • Save Qvatra/270081b04793cfe86c59 to your computer and use it in GitHub Desktop.
Save Qvatra/270081b04793cfe86c59 to your computer and use it in GitHub Desktop.
ionic development: MyController.ts
/// <reference path='../_reference.ts'/>
interface IMyControllerScope extends ng.IScope {
vm: IMyController; // now our view model (vm) in the scope is typed
}
interface IMyController {
myString: string;
myFunction: (arg) => boolean;
}
class MyController implements IMyController {
myString: string = ‘initial value’;
// $inject annotation. It provides $injector with information about dependencies to be injected into constructor
// it is better to have it close to the constructor, because the parameters must match in count and type.
// See http://docs.angularjs.org/guide/di
public static $inject = [
"$scope",
"$rootScope“
];
constructor(
private $scope: IMyControllerScope,
private $rootScope: IAppRootScopeService
) {
var currentClass: MyController = this;
$scope.vm = this;
$scope.$on("$destroy", () => {
// Clean up detached Dom elements
// Clean up attached listeners
});
currentClass.myString = 'assigning variables here';
}
myFunction(arg): boolean {
// arg processing here
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment