显示隐藏股利AngularJs [英] Show Hide Div AngularJs

查看:92
本文介绍了显示隐藏股利AngularJs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是太奇怪了,我不知道为什么这个简单的场景是行不通的。我还是相当新的角度与jQuery和骨干后的生活。

This is so strange and I have no idea why this simple scenario isn't working. I'm still fairly new to Angular after a life with jQuery and Backbone.

这里的code的基本结构...

Here's the basic structure of the code...

<div class="span10" ng-controller="ClientCtrl" ng-hide="addClient">
  <button ng-click="addClient = true" class="btn btn-primary">
    Add new Client
  </button>
</div>
<div class="span10" ng-controller="ClientCtrl" ng-show="addClient">
  <div ng-include src="'views/partials/client.html'"></div>
</div>

预期的行为是,点击添加新客户按钮,将显示第二个div。实际的行为是第一个div获取隐藏(因为它应该),但第二个div保持隐藏。有控制器中没有控制的行为。

The expected behavior is that clicking the 'Add New Client' button will show the second div. The actual behavior is that the first div gets hidden (as it should) but the second div stays hidden. There is no controlling behavior in the controller.

我曾与一个范围函数试了一下,设置在控制器和许多其他事物属性的初始没有任何运气。我究竟做错了什么?我检查,以确保他们在相同的范围,并没有似乎是问题。谢谢你,因为这是推动我疯了帮助。

I've tried it with a scope function, setting the initial in the property in the controller and numerous other things without any luck. What am I doing wrong? I've checked to be sure they are on the same scope and that doesn't "seem" to be the problem. Thanks for the help because this is driving me crazy.

推荐答案

AngularJS在这种情况下创建两个单独的控制器为您映射使用NG-控制器属性的两个控制器。一个控制器内的范围不影响第二的范围。

AngularJS creates two separate Controllers in this case as you have mapped two controllers using ng-controller attribute. The scope within one controller does not affects the scope of second.

您必须做这样的事情:

<div ng-controller="ClientCtrl">
  <div class="span10" ng-hide="addClient">
    <button ng-click="addClient = true" class="btn btn-primary">
      Add new Client
    </button>
  </div>
  <div class="span10" ng-show="addClient">
    <div ng-include src="'views/partials/client.html'"></div>
  </div>
</div>

这篇关于显示隐藏股利AngularJs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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