Skip to content

Instantly share code, notes, and snippets.

@kfiil
Created January 13, 2015 18:45
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 kfiil/de2a712945a5f974be1c to your computer and use it in GitHub Desktop.
Save kfiil/de2a712945a5f974be1c to your computer and use it in GitHub Desktop.
AngularJS kursus, custom directive isolate scope with controller
angular.module('directivesModule')
.directive('isolateScopeWithController',function(){
return {
restrict:'EA',
scope: {datasource:'=',add:'&'},
controller: function($scope){
function init() {
$scope.customers=angular.copy($scope.datasource);
}
init();
$scope.addCustomer=function(){
//Call external scope's function
$scope.add();
//Add new customer to directive scope
$scope.customers.push({…});
};
},
template: '<button ng-click="addCustomer()">Change Data</button><ul>' +
'<li ng-repeat="cust in customers">{{ cust.name }}</li></ul>'
};
});
<div isolate-scope-with-controller></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment