Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div ng-include="'item.html'"
- ng-controller="ItemController"
- onload="item = rightItem">
- </div>
- $scope.dataHolder = {};
- $scope.dataHolder.leftItem = items.leftItem;
- $scope.dataHolder.rightItem = items.rightItem;
- <div ng-include="'item.html'"
- ng-if="true"
- onload="item = rightItem">
- </div>
- <div ng-include="'item.html'"
- ng-if="true"
- onload="item = leftItem">
- </div>
- .directive('ngIncludeTemplate', function() {
- return {
- templateUrl: function(elem, attrs) { return attrs.ngIncludeTemplate; },
- restrict: 'A',
- scope: {
- 'ngIncludeVariables': '&'
- },
- link: function(scope, elem, attrs) {
- var vars = scope.ngIncludeVariables();
- Object.keys(vars).forEach(function(key) {
- scope[key] = vars[key];
- });
- }
- }
- })
- <div ng-include-template="'item.html'" ng-include-variables="{ item: 'whatever' }"></div>
- <div ng-include-template="'item.html'" ng-include-variables="{ item: variableWorksToo }"></div>
- .directive(
- 'ngIncludeTemplate'
- () ->
- {
- templateUrl: (elem, attrs) -> attrs.ngIncludeTemplate
- restrict: 'A'
- scope: {
- 'ngIncludeVariables': '&'
- }
- link: (scope, elem, attrs) ->
- vars = scope.ngIncludeVariables()
- for key, value of vars
- scope[key] = value
- }
- )
- <div ng-include='myFile.html' ng-init="myObject = myCtrl.myObject; myOtherObject=myCtrl.myOtherObject"/>
- .directive('ngIncludeTemplate', function() {
- return {
- templateUrl: function(elem, attrs) { return attrs.ngIncludeTemplate; },
- restrict: 'A',
- scope: {
- 'ngIncludeVariables': '&'
- },
- link: function(scope, elem, attrs) {
- var cache = scope.ngIncludeVariables();
- Object.keys(cache).forEach(function(key) {
- scope[key] = cache[key];
- });
- scope.$watch(
- function() {
- var val = scope.ngIncludeVariables();
- if (angular.equals(val, cache)) {
- return cache;
- }
- cache = val;
- return val;
- },
- function(newValue, oldValue) {
- if (!angular.equals(newValue, oldValue)) {
- Object.keys(newValue).forEach(function(key) {
- scope[key] = newValue[key];
- });
- }
- }
- );
- }
- };
- });
- <script type="text/ng-template" id="partial">{{variable}}</script>
- <div ng-include-template="'partial'" ng-include-variables="{variable: variable}"></div>
- templateUrl: function(elem, attrs) { return attrs.ngIncludeTemplate; },
- template: function(elem, attrs) { return document.getElementById(attrs.ngIncludeTemplate.split("'")[1]).innerHTML },
Add Comment
Please, Sign In to add comment