I want to reload my controller to get the recent values passed to service.js

This is my Parent html page-
I am showing a tree structure on parent page which I get from child html page

<div ng-controller="domainController">
<div>
<!--It takes the controller data through tree-data tag, I want this data to get refreshed whenever new data is passed through child html page so that it will have the new data which is stored in service    -->
<swt-tree tree-data="busdomain" on-select="statementSelected(branch, selected_branches)" tree-control="statementTree" label-provider="domainLabelProvider" content-provider="domainContentProvider" expand-level="-1"></swt-tree>
</div>

This is my Child html
On click of OK button I want my values to populate on parent.html page

<form  name="businessdomain" ng-controller="domainController">
<input id="name" placeholder="Name" ng-model="busdomain.name" ng-change="domainNameChanged()" required="true"> 
<!--I am making a tree like structure that is why this tags are used through tree-data statements am passing the controller values to html page for populating the data on tree --> 
<swt-tree tree-data="statements" on-select="statementSelected(branch, selected_branches)" tree-control="statementTree" label-provider="domainLabelProvider" content-provider="domainContentProvider" expand-level="-1"></swt-tree>
<!--Am calling controller method which will perform tree operations-->
 <button  type="submit" ng-click="addSubTree(createdomain.$valid)">OK</button>

This is my controller.js
I want my controller to get reload as the values which are stored in service gets passed to parent page through my scope.busdomain variable when reloaded

controller('domainController', ['$scope', '$state', 'DomainNameService', function($scope, $state, DomainNameService) {  
    $scope.activeTab = 1;
    $scope.currentBDStatement=[];
    $scope.statements=[];
    $scope.childBD =[];
    var statementTree = {};
<!--through this busdomain variable I am passing the values to parent html file but when I am passing the values added from child html to parent html page I am not getting the value recently added, this comes when i refresh the page(i need a way to reload this controller as the values from service reflects after refreshing the page or on reloading the page) -->
    $scope.busdomain = DomainNameService.getBusDomainName();
<!--This is the method which i call on click of OK of child html -->
$scope.addSubTree = function(val){
            var varType = "busDomain";
            var busDomain=$scope.busdomain.name;
            var parent = DomainNameService.getDomainName()[0];
<!--Adding the values got from child html page to service -->
            DomainNameService.addChildBD(busDomain);
            $scope.childBD=DomainNameService.getChildBD();
            $scope.currentBDStatement.push($scope.busdomain.name);
            $scope.currentDomainName=$scope.getBusDomain($scope.childBD,parent,varType);
            $scope.statements.push($scope.currentDomainName);
            $scope.statementTree.setNewInput($scope.statements);
            DomainNameService.addBusDomain($scope.statements);
            <!--Redirecting to my parent page --> 
            $state.go('BusDomainTree');
        }

    $scope.getBusDomain = function(stType,parent,varType) {
        return {node:[{name:parent}],name:parent, childNode:stType, refType: varType};
    }
}])

This is my service.js
here I am storing all the values which I get from child html page.

app.factory('DomainNameService', function() {
var childDomainName=[];
<!--Adding the child html values through controller method -->
  addChildBD: function(childBD){
        childDomainName.push(childBD);
      },
<!--I get the recent values when the page is reload, this is the problem which i am facing -->
 getChildBD: function(){
        return childDomainName;
    },
}


Source: html5

Leave a Reply