如何从一个页面传递值到另一页中的角? [英] how to pass the value from one page to another page in angular?

查看:116
本文介绍了如何从一个页面传递值到另一页中的角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的角度首发,当我传球,我正在进入文本框,我能够看到 pageA的[\\后台管理]关于头文字=价值的价值但是当我从一个页面路由到另一页我不能够看到页面B相同的文本[\\仪表板] 。在我们的应用程序的头是共同所有页。

\r
\r

/ * * pageA的/\r
 $ rootScope.accNo =功能(){\r
    返回$ scope.AccountNumber;\r
 }\r
\r
/ * *页面B /\r
  $ scope.showAccNo =功能(){\r
    返回$ scope.accno = $ rootScope.accNo();\r
  }

\r

<! - 'pageA` - >\r
 < D​​IV CLASS =COL-MD-12>\r
      <输入类型=密码级=表格控占位=#####NG模型=账户号码/>\r
 < / DIV>\r
&所述;! - `pageB` - >\r
  < P>管理员门户:其中;强> {{showAccNo()}}< / STRONG>< / P>

\r

\r
\r


解决方案

您可以通过使用angularjs的服务

  angular.module('对myApp',[])
    。服务('sharedProperties',函数(){
        VAR账户号码;        返回{
            的getProperty:功能(){
                返回账户号码;
            },
            的setProperty:函数(值){
                账户号码=值;
            }
        };
    });
功能CTRLA($范围,sharedProperties){
       sharedProperties.setProperty($ scope.AccountNumber);
}功能CTRLB($范围,sharedProperties){
       $ scope.accno = sharedProperties.getProperty();
}
 &所述;! - `pageA` - >
 < D​​IV CLASS =COL-MD-12>
     <输入类型=密码级=表格控占位=#####NG模型=账户号码/>
 < / DIV>&所述;! - `pageB` - >
< P>管理员门户:其中;强> {{ACCNO}}< / STRONG>< / P>

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*/   
 $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>

解决方案

you can pass values to other controllers using angularjs service

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>

这篇关于如何从一个页面传递值到另一页中的角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆