带范围变量的 ng-show 的正确语法是什么

What is the right syntax for ng-show with scope variable

我正在设置一个 ng-show 以在我处于特定状态时显示我的删除按钮。

但它不起作用。我检查了控制台,我的方法将 true 传递给范围变量。仍然不确定出了什么问题。

application.html

      <ul class="nav navbar-nav navbar-right">
        <li ng-show="notesState" ><a  ng-really-message="Are you sure you want to delete this note?" ng-really-click="deleteNote(note)" class="glyphicon glyphicon-trash "  style="float:left;" >Delete note</a></li>
        <li><a href="#/home" >+ New Note</a></li>
        <li ng-hide="signedIn"><a href="#/login">Login</a></li>
        <li ng-show="signedIn"><a href="#/home">{{user.email}}</a></li>
        <li class="pointer" ng-show="signedIn"><a ng-click="logout()">Logout</a></li>
      </ul>

在notesCtrl.js

$scope.notesState = $state.is('notes')

控制器加载时notesState是否为真?你可能需要 $scope.$apply() 如果它在控制器加载时为假但稍后变为真。

有时 return 一个函数可以工作,但我真的不知道你为什么需要这样做。

$scope.notesState = function(){ return $state.is('notes') }

ng-show="notesState()"

这里是 $state.is 函数有时 returns

$state.is = function is(stateOrName, params, options) {
  options = extend({ relative: $state.$current }, options || {});
  var state = findState(stateOrName, options.relative);

  if (!isDefined(state)) { return undefined; }
  if ($state.$current !== state) { return false; }
  return params ? equalForKeys(state.params.$$values(params), $stateParams) : true;
};

function equalForKeys(a, b, keys) {


 if (!keys) {
    keys = [];
    for (var n in a) keys.push(n); // Used instead of Object.keys() for IE8 compatibility
  }
  for (var i=0; i<keys.length; i++) {
    var k = keys[i];
    if (a[k] != b[k]) return false; // Not '===', values aren't necessarily normalized
  }
  return true;
}

如果这有助于任何人调查此问题。

尝试使用这个 way.May 如果它有效。

<li ng-show="notesState=='true'" >