Last active
August 29, 2015 14:12
-
-
Save MichalZalecki/3ed6d99640379b8e064e to your computer and use it in GitHub Desktop.
AngularJS: Isolated scope and function parameter
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
<!DOCTYPE html> | |
<html ng-app="myApp" ng-controller="myApp.myCtrl"> | |
<head> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.js"></script> | |
<meta charset="utf-8"> | |
<title>AngularJS: Isolated scope and function parameter</title> | |
</head> | |
<body> | |
<h1>AngularJS: Isolated scope and function parameter</h1> | |
<a href="http://jsbin.com/qeqezaqaxo/4/edit?html,js,console">see at jsBin</a> | |
<p>Look at the <strong>console</strong>!</p> | |
<car passengers="people" with-passenger="greet"></car> | |
<bus passengers="people" with-passenger="greet2(name)"></bus> | |
</body> | |
</html> |
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 'myApp', [] | |
.controller 'myApp.myCtrl', ['$scope', ($scope) -> | |
$scope.people = [ | |
'Michal', | |
'Piotr', | |
'Ala' | |
] | |
$scope.greet = (name) -> | |
console.log "Hi #{name}!" | |
$scope.greet2 = (name) -> | |
console.log "Hello #{name}!" | |
] | |
# passing function without invoking | |
.directive 'car', -> | |
restrict: 'E' | |
scope: { | |
passengers: '=' | |
withPassenger: '&' | |
} | |
link: (scope) -> | |
scope.withPassenger()(person) for person in scope.passengers | |
# passing object | |
.directive 'bus', -> | |
restrict: 'E' | |
scope: { | |
passengers: '=' | |
withPassenger: '&' | |
} | |
link: (scope) -> | |
scope.withPassenger({name: person}) for person in scope.passengers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment