Created
January 13, 2015 18:45
-
-
Save kfiil/de2a712945a5f974be1c to your computer and use it in GitHub Desktop.
AngularJS kursus, custom directive isolate scope with controller
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
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