0

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]
18
  • format your code well in it's container, thanks. Commented Mar 31, 2018 at 18:02
  • i have edited the post and added the html file Commented Mar 31, 2018 at 18:47
  • when i change your function to loadHistory(); it works for me, check out. Commented Mar 31, 2018 at 18:51
  • sorry i updated that, loadHistory(), when i call this method then i get data using Rest , and i update orderItem scope with that data. but unable to reflect in html page. Commented Mar 31, 2018 at 18:52
  • 1
    @rupeshkumar you haven't provided sufficient infos, and the code you linked is not syntactic, we look for more infos from your side. Commented Mar 31, 2018 at 19:13

1 Answer 1

0

Your code works fine.

If I work off your mysterious REST call with my proper changes into it, the template gets changed accordingly because $scope.$apply(); has for role to update the controller after each json call.

check here I hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.