Angularjs双向绑定不起作用

时间:2014-06-29 22:11:04

标签: angularjs coffeescript

我正在尝试记录变量,这是输入框的模型,但它表示未定义,这是coffeescript代码。

.controller('setupCtrl',[
  '$scope'
  ($scope) ->
    $scope.userAge = [{age: ''}]
    console.log 2342424

    $scope.addAge = ->
      console.log($scope.age)
])

这是HTML代码

<form role="ageForm" data-ng-submit="addAge()" >
    <div class="form-group">
        <input type="text" ng-model="age" class="form-control" placeholder="Age" required>
    </div>
    {{input}} butona koyup data-ng-click dene istersen
    <button type="submit" ng-click="addAge()">sdsadsdSave</button>
</form>

$ scope.age

表示未定义

1 个答案:

答案 0 :(得分:1)

看起来像ng-model =&gt; userAge.age不仅仅是年龄

<form role="ageForm" data-ng-submit="addAge()" >
    <div class="form-group">
        <input type="text" ng-model="userAge.age" class="form-control" placeholder="Age" required>
    </div>
    {{input}} butona koyup data-ng-click dene istersen
    <button type="submit" ng-click="addAge()">sdsadsdSave</button>
</form>

$scope.addAge = ->
      console.log($scope.userAge.age)