Created
May 6, 2015 16:47
-
-
Save icfantv/cc60e677ce01975e1bd6 to your computer and use it in GitHub Desktop.
ControllerAs Syntax
This file contains hidden or 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
<html> | |
<head> | |
<!-- include angular --> | |
</head> | |
<body data-ng-app='app'> | |
<div data-ng-controller='MyController as MyController'> | |
<!-- bound once --> | |
Controller Loaded: {{ ::MyController.someModel.controllerLoaded }} | |
<hr/> | |
<!-- two-way binding --> | |
Name: {{ MyController.someModel.name }} | |
</div> | |
</body> | |
</html> |
This file contains hidden or 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
var app = angular.module('app', []); | |
app.service('MyService', [MyService]); | |
app.controller('MyController', ['MyService', MyController]); | |
function MyService() { | |
this.serviceFunction = function() { | |
console.log('in service function'); | |
} | |
} | |
function MyController(MyService) { | |
var vm = this; | |
vm.someModel = { | |
id: '123', | |
name: 'steve', | |
mood: 'happy', | |
controllerLoaded: true | |
}; | |
MyService.serviceFunction(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment