在我的 html 中使用 rootScope 变量 [英] Use rootScope variables in my html

查看:33
本文介绍了在我的 html 中使用 rootScope 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我们可以像这样轻松地在 Angular html 中使用范围变量:

<头><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script><身体><div><标签>名称:</label><input type="text" ng-model="yourName" placeholder="在此处输入名称"><小时><h1>你好{{yourName}}!</h1>

</html>

例如:

你好{{yourName}}!

正在使用我希望使用的范围内的 yourName:

<h1>你好 {{yourName}} 你在 {{$rootScope.zoneName}}!</h1>

是否可以像这样引入 $rootScope 变量?

解决方案

您不需要在 html 中指定 $rootScope.您可以像使用 $scope 变量

一样使用它

刚刚更新

<h1>你好 {{yourName}} 你在 {{$rootScope.zoneName}}!</h1>

你好{{yourName}}你在{{zoneName}}!</h1>

So we can use scope variables in our angular html easily like this:

<!doctype html>
<html ng-app>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
  </head>
  <body>
    <div>
      <label>Name:</label>
      <input type="text" ng-model="yourName" placeholder="Enter a name here">
      <hr>
      <h1>Hello {{yourName}}!</h1>
    </div>
  </body>
</html>

So for example:

<h1>Hello {{yourName}}!</h1>

Is using yourName from the scope I was hoping to do:

<h1>Hello {{yourName}} you are in in {{$rootScope.zoneName}}!</h1>

Is it possible to bring $rootScope variables in like this?

解决方案

You do not need to specify $rootScope in html. You can use it the same way as you use $scope variables

Just update from

<h1>Hello {{yourName}} you are in in {{$rootScope.zoneName}}!</h1>

to

<h1>Hello {{yourName}} you are in in {{zoneName}}!</h1>

这篇关于在我的 html 中使用 rootScope 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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