renaming a variable in ng-include [duplicate]
ng-include reads the variables within the global scope. You cannot use that. It won't work.
And do not use onload
because it litters the global scope.
The cleaner solution is to make a new generic directive
Here's the ideal usage:
<div ng-include-template="'app/views/order.html'" ng-include-variables="{ order: trade.order }"></div>
The directive is:
.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
}
)
You can see that the directive doesn't use the global scope. Instead, it reads the object from ng-include-variables and add those members to its own local scope.
I hope this helps. It's clean and generic.