2014-01-12 57 views
0

为什么我不能使用函数更改值? AngularJS为什么我不能使用函数来改变值? AngularJS

HTML:

<div ng-controler='TestCtrl' id='TestCtrl'> 
    <h1>Test: {{test.name}}</h1> 

    <div ng-hide='showTest'> 
     <div class='content'> 
      <p>First name: <input ng-model='firstName'></p> 
      <p>Last name: <input ng-model='lastName'></p> 
     </div> 
     <div jq-ui-button ng-click='doSth()'> 
      Do something 
     </div> 
    </div> 
</div> 

JS:

app.controller('TestCtrl', function ($scope) { 
    $scope.showTest = false; 
    $scope.test = {name:'Test name'}; 

    $scope.doSth = function() { 
     $scope.showTest = true; 
    } 
} 

它不工作。但是当我写:

<div jq-ui-button ng-click='showTest = true'> 

它的工作。

问题在哪里?

回答

0

您必须编写ng-controller而不是ng-controler。这就是为什么你的代码没有被使用。 HTML中的第一行。

+0

谢谢。我搜索了错误时间。 – Niezborala

+0

@Niezbor我也知道这些情况:) – michael

相关问题