Last active
August 29, 2015 14:05
-
-
Save aaronfrost/e40e9aaac38778885423 to your computer and use it in GitHub Desktop.
Multiple Scopes - JS
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
<!--Parent Controller--> | |
<div ng-controller="ParentController"> | |
<!--First Child Controller--> | |
<div ng-controller="ChildAController"> | |
<button ng-click="handleClick()">Click This</button> | |
</div> | |
<!--Second Child Controller--> | |
<div ng-controller="ChildBController"> | |
<button ng-click="handleClick()">Click This</button> | |
</div> | |
</div> |
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.controller('ParentController', function($scope){ | |
}); | |
app.controller('ChildAController', function($scope, fooService){ | |
$scope.handleClick = function(e){ | |
doControllerSpecificThings(); | |
fooService.doAGenericThing(); | |
}; | |
function doControllerSpecificThings(){ | |
//things that are for this controller here | |
} | |
}); | |
app.controller('ChildBController', function($scope, fooService){ | |
$scope.handleClick = function(e){ | |
doControllerSpecificThings(); | |
fooService.doAGenericThing(); | |
}; | |
function doControllerSpecificThings(){ | |
//things that are for this controller here | |
} | |
}); | |
app.factory('fooService', function(){ | |
return { | |
doAGenericThing : function(){ | |
console.log("Don't cry anymore. This is how you share code."); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't do this. Use a service.