Created
January 30, 2016 17:44
-
-
Save sanketmaru/6025bcd69a9384e46d75 to your computer and use it in GitHub Desktop.
Angular Isolated Scope
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
<!DOCTYPE html> | |
<html ng-app="app"> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body ng-controller="MyAppController"> | |
<outer twowayvar="twoWayBindingVar" demo-function="demoFunction()" inner-demo-function='innerDemoFunction()'> | |
</outer> | |
</body | |
</html> | |
<script id="jsbin-javascript"> | |
angular.module('app', []) | |
.controller('MyAppController', ['$scope', function($scope) { | |
$scope.twoWayBindingVar = "this is a two way bind string"; | |
$scope.oneWayBindVar = "this is a one way bind string"; | |
// calling from directive | |
$scope.demoFunction = function() { | |
//alert("Inside demo function in controller"); | |
}; | |
$scope.innerDemoFunction = function(){ | |
console.log("Inside inner demo function"); | |
}; | |
}]) | |
.directive('outer', function() { | |
return { | |
restrict: "EA", | |
scope: { | |
twowayvar: "=", | |
innerDemoFunction: "&", | |
demoFunction: "&", | |
}, | |
replace:true, | |
template: "<div><input type='text' ng-model='twowayvar'> </input> <inner inner-demo-function='innerDemoFunction()' twowayvar='twowayvar'></inner></div>", | |
link: function(scope, element, attrs) { | |
scope.demoFunction(); | |
} | |
}; | |
}) | |
.directive('inner', function() { | |
return { | |
restrict: "EA", | |
scope: { | |
innerDemoFunction: "&", | |
twowayvar:"=" | |
}, | |
replace:true, | |
template: "<div><input type='text' ng-model='twowayvar'> </input> </div>", | |
link: function(scope, element, attrs) { | |
scope.innerDemoFunction(); | |
} | |
}; | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">angular.module('app', []) | |
.controller('MyAppController', ['$scope', function($scope) { | |
$scope.twoWayBindingVar = "this is a two way bind string"; | |
$scope.oneWayBindVar = "this is a one way bind string"; | |
// calling from directive | |
$scope.demoFunction = function() { | |
//alert("Inside demo function in controller"); | |
}; | |
$scope.innerDemoFunction = function(){ | |
console.log("Inside inner demo function"); | |
}; | |
}]) | |
.directive('outer', function() { | |
return { | |
restrict: "EA", | |
scope: { | |
twowayvar: "=", | |
innerDemoFunction: "&", | |
demoFunction: "&", | |
}, | |
replace:true, | |
template: "<div><input type='text' ng-model='twowayvar'> </input> <inner inner-demo-function='innerDemoFunction()' twowayvar='twowayvar'></inner></div>", | |
link: function(scope, element, attrs) { | |
scope.demoFunction(); | |
} | |
}; | |
}) | |
.directive('inner', function() { | |
return { | |
restrict: "EA", | |
scope: { | |
innerDemoFunction: "&", | |
twowayvar:"=" | |
}, | |
replace:true, | |
template: "<div><input type='text' ng-model='twowayvar'> </input> </div>", | |
link: function(scope, element, attrs) { | |
scope.innerDemoFunction(); | |
} | |
}; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment