我想重新加载我的控制器以获取传递给service.js的最新值

时间:2015-05-21 08:07:12

标签: angularjs html5

这是我的父html页面 - 我在父页面上显示了一个树结构,我从子html页面

<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>

这是我的儿童HTML 点击“确定”按钮后,我希望我的值填充在parent.html页面上

<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>

这是我的controller.js 我希望我的控制器能够重新加载,因为存储在服务中的值在重新加载时会通过我的scope.busdomain变量传递给父页面

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};
    }
}])

这是我的service.js 在这里,我存储了从子html页面获得的所有值。

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;
    },
}

0 个答案:

没有答案