简体   繁体   English

AngularJS-无法将值从控制器传递到视图

[英]AngularJS - Trouble Passing Values from Controller to View

Note: I am new to Angular, but I have a general understanding of what's going on. 注意:我是Angular的新手,但是我对所发生的事情有一个大致的了解。

I have a I want to hide when a function returns true. 我有一个我想在函数返回true时隐藏。

<div ng-hide="disableElement()">

In my controller I have a function. 在我的控制器中,我有一个功能。

$scope.disableElement = function () {
    //Logic...
    return true;
}

Even setting this to just return true for debugging won't hide it, but ng-hide"true" does hide it. 即使将其设置为仅返回true进行调试也不会将其隐藏,但是ng-hide"true"会隐藏它。

Inspecting the $scope using the AngularJS Batarang shows disableElement: null . 使用AngularJS Batarang检查$ scope会显示disableElement: null Is this expected? 这是预期的吗?

Ideally, I want to be passing in parameters into this function, but right now I can't even get it to return a value back to the view. 理想情况下,我想将参数传递给此函数,但是现在我什至无法获取将值返回给视图的信息。

Any idea why I can't pass back values? 知道为什么我不能传回值吗?

Thanks! 谢谢!

<div ng-click="disableElement('HELLO')"><div>
<div ng-hide="disabled == true"></div>   

Function: 功能:

$scope.disabled = false; 

$scope.disableElement = function (param) {

  // set to true
  $scope.disabled = true;
  console.log(param);  

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM