In a custom directive I am updating the scope (to update the scope("orderItem") I click on button on HTML file(templateUrl) which call the function to update the scope ) and displaying in the templateUrl, so for this I need to reload the html page (templateUrl) how to reload it ? following is my sample code.
##main.js
.directive('orderItemDetails', function () {
return {
restrict: 'E',
scope: {
orderItem: '=', // this scope is injected from some other js file.
},
templateUrl: 'orders/orderItemDetails/orderItemDetails.html', // in this html file i am displaying the "orderItem" (scope) data.
// RUPESH
controller: function ($scope) {
$scope.loadHistory = function () { // function loadHistory() is called when button on orderItemDetails.html is clicked
// from REST call i get data here, using this data i update the "orderItem" scope.
function (data) {
$scope.orderItem.history = data.statusHistory;// here i am updating the "orderItem" (scope).
$scope.$apply();
},
function (code, text, xhr) {
});
}
}
};
})
// here the scope orderItem is injected before calling the loadHistory() method
##details.html
<order-item-details> // again this data comes from somewhere else
order-item="selectedOrderComponents.fulfilmentOrderItem.data">
</order-item-details>
// following html file include the html file which displays the data
##orderItemDetails.html
<ng-include src="'orders/orderItemDetails/orderItemHistory.html'"></ng-include>
##orderItemHistory.html // the file to display the data
<button class="btn btn-default" ng-click="loadHistory()">Load History<i class="fa fa-refresh"></i>
</button>
<table>
<tbody>
// here from scope "orderItem" the data is displyed
<tr ng-repeat="statusChange in orderItem.orderItem.history.statusChanges">
<td>{{statusChange.changeDate | date: dateMask}}</td>
<td>{{statusChange.status}}</td>
<td>{{statusChange.subStatus}}</td>
<td>{{statusChange.errorCode}}</td>
<td>{{statusChange.errorDescription}}</td>
</tr>
</tbody>
</table>
I want the updated "orderItem" (scope) value to be displayed in the orderItemDetails.html file.
but its not working right now. whats wrong ?
[I am using AngularJS 1]
loadHistory();it works for me, check out.