ng-click fired函数但无法更改$ scope.var

时间:2015-03-12 12:42:12

标签: javascript angularjs

<!doctype html>
<html ng-app>
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
    <script src="script.js"></script>

  </head>
  <body>

<ul class="list">


  <li class="item">
     Room Types & Prices
     <button ng-click="editMode=true" ng-hide="editMode" class="editBtn">Edit</button>
     <button ng-show="editMode" class="ion-plus addBtn" data-pack="default"></button>

  </li>


<div class="inputRowWrap" ng-show="editMode">
      <div class="row">
        <div class="col col-40">

<label class="item item-input">
          <input type="text" placeholder="Room #1">
        </label>

        </div>

        <div class="col col-40">

<label class="item item-input">
          <input type="text" placeholder="RM">
        </label>

        </div>

                <div class="col">

<select>
              <option selected="">1 pax</option>
              <option>2 pax</option>
              <option>3 pax</option>
              <option>4 pax</option>
              <option>5 pax</option>
              <option>6 pax</option>
            </select>
</div>

      </div>

            <div class="padding saveBtnWrap">
        <button ng-click="saveSetting()" class="button button-block button-positive">Save</button>
      </div>

      </div>




</ul>
<hr>
{{editMode}}
</html>

  $scope.saveSetting = function(){
    $scope.editMode = false;
  }
}

我的$ scope.editmode没有改变它的值,我发出一个警告,该函数确实触发了。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在html中添加ng-controller

<body ng-controller="Ctrl">

Working example