1

I’m trying to log variable which is the model of inputbox, but it says undefined, here is the coffeescript code.

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

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

This is the HTML code

<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>

It says undefined for $scope.age

1 Answer 1

1

It looks like ng-model => userAge.age not age only

<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)
Sign up to request clarification or add additional context in comments.

5 Comments

thank you sylwester, it works, now i would like to know that how can i store this is in variable which is not defined in script?
i'm bit confused can you explain bit more please ?
sylwester suppose that i have an input <input ng-model="x"> but x is not defined in $scope, how can i log it?
I belive is good practice to define you model in controller. But even if you didn't defined model in controller, everything should works please see here: jsbin.com/veyix/1. another but is coffescript, it looks like it didn't worked for you.
Does it work with an object like that? I've use ng-model to define a string or int but never var.int

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.