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.
include-variables
data as static. It won't track changes that occur in the parent scope. With a lot more effort, you could actually have 2-directional binding of changes to theinclude-variables
data: https://mcmap.net/q/89055/-angularjs-how-to-render-a-partial-with-variables – Married