如何使用angular js

时间:2015-05-15 07:01:13

标签: html angularjs angularjs-scope

我有一个父页面,其中通过一个链接出现一个弹出窗口,我想在按下确定按钮时将输入值传递给父页面。我也使用服务来存储值,但我认为在页面加载时调用服务方法,因为我必须将值从子节点传递给父节点,因此页面不会再次加载,因此值不会持久存在。任何人都可以帮助我。

这是我的父页面:

<!-- Here I want to show the values which I got from child. But in tree-data="domain"
     I am not getting the values which i pass from child html -->
<swt-tree tree-data="domain" 
          tree-control="statementTree" 
          label-provider="domainLabelProvider" 
          content-provider="domainContentProvider" 
          expand-level="-1">
</swt-tree>

<!-- Here My Child html will load -->
<div ui-view></div>

这是我的Child.html

<form ng-controller="domainController">
  <input type="text" 
         ng-model="busdomain.name" 
         ng-change="nameChanged()">


  <!-- Here in tree-data="statements" I am getting the values passed from Child.html -->
  <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> 

  <button type="submit" ng-click="addSubTree(createdomain.$valid)">OK</button>
</form>

这是我的controller.js

controller('domainController', ['$scope', '$state', 'DomainNameService', function($scope, $state, DomainNameService) {  
    $scope.activeTab = 1;
    $scope.statements=[];
    var statementTree = {};
    $scope.statementTree = statementTree = {};
    $scope.domain = DomainNameService.getDomainName();
    $scope.addSubTree = function(val){
var varType = "busDomain";
                    var domain=[];
                    var busDomain=$scope.busdomain.name;
                    var parent = DomainNameService.getDomainName()[0];              $scope.currentDomainName=$scope.getBusDomain(busDomain,parent,varType);
                        $scope.statements.push($scope.currentDomainName);
                        $scope.statementTree.setNewInput($scope.statements);
                        DomainNameService.addBusDomain($scope.busdomain.name); 
                        $scope.domain.domainName = DomainNameService.getBusDomainName[0];
    //I am passing values here to service but later on this values resets to some previous value..I don't know how to persist the values in $scope.domain.domainname
                    $state.go('DomainTree');
                }
    $scope.getBusDomain = function(stType,parent,varType) {
            return {node:[{name:parent}],name:parent, child:[{name:stType,refType: varType}], childNode:stType, refType: varType};  
        }

这是我的Service.js

app.factory('DomainNameService', function() {
    var busDomainValue=[];      
    var busDomain = undefined;
    return{     
    addBusDomain: function(busDomName){
        busDomainValue.push(busDomName);
    },
   getBusDomainName: function(){
        return busDomainValue;
    }
    }
})

请有人帮我解决这个问题。提前谢谢。

0 个答案:

没有答案