如何将值从一个页面传递到另一个页面?

时间:2022-12-29 11:52:16

I am starter of angular, when i am passing the value that i am entering into textbox i am able to see text="value" on header in pageA[\adminlogin] but when i am routing from one page to another page i am not able to see the same text on pageB[\dashboard] .In our application header is common for all pages.

我先发角,当我通过我进入文本框的值,我可以看到文本=“价值”在pageA头(\ adminlogin),但当我路由从一个页面到另一个页面我不能够看到相同的文本pageB(\ dashboard)在我们的应用程序中所有页面的标题是很常见的。

/*pageA*/   
 $rootScope.accNo = function() {
    return $scope.AccountNumber;
 }

/*pageB*/   
  $scope.showAccNo = function() {
    return $scope.accno = $rootScope.accNo();
  }
<!-- `pageA` -->
 <div class="col-md-12">
      <input type="password" class="form-control" placeholder="#####"  ng-model="AccountNumber"/>
 </div>
<!-- `pageB` -->
  <p >Administrator Portal for:<strong>{{showAccNo()}}</strong></p>

1 个解决方案

#1


3  

you can pass values to other controllers using angularjs service

您可以使用angularjs服务将值传递给其他控制器

angular.module('myApp', [])
    .service('sharedProperties', function () {
        var AccountNumber;

        return {
            getProperty: function () {
                return AccountNumber;
            },
            setProperty: function(value) {
                AccountNumber= value;
            }
        };
    });
function CtrlA($scope, sharedProperties) {
       sharedProperties.setProperty($scope.AccountNumber);
}

function CtrlB($scope, sharedProperties) {
       $scope.accno = sharedProperties.getProperty();
}


 <!-- `pageA` -->
 <div class="col-md-12">
     <input type="password" class="form-control" placeholder="#####"  ng-model="AccountNumber"/>
 </div>

<!-- `pageB` -->
<p >Administrator Portal for:<strong>{{accno}}</strong></p>

#1


3  

you can pass values to other controllers using angularjs service

您可以使用angularjs服务将值传递给其他控制器

angular.module('myApp', [])
    .service('sharedProperties', function () {
        var AccountNumber;

        return {
            getProperty: function () {
                return AccountNumber;
            },
            setProperty: function(value) {
                AccountNumber= value;
            }
        };
    });
function CtrlA($scope, sharedProperties) {
       sharedProperties.setProperty($scope.AccountNumber);
}

function CtrlB($scope, sharedProperties) {
       $scope.accno = sharedProperties.getProperty();
}


 <!-- `pageA` -->
 <div class="col-md-12">
     <input type="password" class="form-control" placeholder="#####"  ng-model="AccountNumber"/>
 </div>

<!-- `pageB` -->
<p >Administrator Portal for:<strong>{{accno}}</strong></p>