当布尔值更改值时,AngularJS,ng-show不起作用

时间:2014-01-16 11:39:09

标签: javascript angularjs ng-show

AngularJS中的HTML页面。 当布尔值设置为true时,我的ng-show不会显示div。

这是我的HTML文件:

<div class="container">
<div ng-if="!query" ng-hide="editBoolean">
    <h3>{{article.id}} - {{article.title}}</h3>
    <h4 ng-bind-html="article.text"></h4>
    <button ng-click="edit(true)">Endre tekst</button>
</div>

<div ng-show="editBoolean">

    <style>
    .ta-editor { 
        min-height: 300px; 
        height: auto; 
        overflow: auto; 
        font-family: inherit; 
        font-size: 100%; 
    } 
    </style> 

    <input type="text" ng-model="article.title" value="{{article.title}}">

    <div text-angular="text-angular" ng-model="article.text"></div>
    <button ng-click="update(article.text, article.title)">Lagre</button>
    <button ng-click="edit(false)">Avbryt</button>

</div>

<div ng-if="query">
    <h3>{{query}}</h3>
</div>  

这是我的controller.js文件:

 // Article controller
wikiControllers.controller('articleController', ['$scope', 'articleService',     '$routeParams', '$sanitize', 
  function($scope, articleService, $routeParams, $sanitize){
$scope.editBoolean = false;
$scope.edit = function(editValue){
  this.editBoolean = editValue;
  console.log(this.editBoolean);
};
  }]);

当我有console.log我的booleanfil时,它显示为true(值已更改)

1 个答案:

答案 0 :(得分:6)

这样:

this.editBoolean = editValue;

应该是:

$scope.editBoolean = editValue;