Here is the relevant html:
<ng-include src="'app/views/order.html'"></ng-include>
Attached to the scope this ng-include
is nested in is a trade variable. The trade variable looks like:
var trade = {
order: {}
}
The problem is that order.html is expecting an order variable not a trade.order
How can I call the ng-include
and pass in trade.order
as order
?
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:
The directive is:
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.
I answered a very similar question yesterday.
Same answer: use a directive with isolated scope
Multiple ngIncludes with Different controls visible
The solution is to create a new directive:
Here is the usage: