moller.peter
moller.peter

Reputation: 115

How can I console.log expression in AngularJS?

As a new "Angularian", I have this:

<div data-ng-app="" data-ng-init="">
    <input type="text" ng-model="hello">
    <p>{{hello}}</p>
</div>

But I wonder, how can I console.log whatever I type in the expression (ng-model)?

(e.g. if I type "Soylent Green is people" in the text field I want to see it in Chrome's Inspector window)

Upvotes: 0

Views: 2875

Answers (3)

Walioul Islam
Walioul Islam

Reputation: 11

Use ng-change directive with your input tag like

<input type="text" ng-model="hello" ng-change="textChange()" >

and in your controller

$scope.textChange = function () {
          console.log($scope.hello);
  }

https://jsfiddle.net/walioulislam/wpjwavrc/

Upvotes: 1

Prashant Pandey
Prashant Pandey

Reputation: 23

You have a controller for this app, if you don't know about controllers you can read the documentation in w3schools You can do console.log($scope.hello) inside your controller By default each and every variable you define in HTML is inside $scope object

Upvotes: 0

w-robot
w-robot

Reputation: 91

You can use console.log($scope.hello); inside your controller.

I suggest you to take a look about Addons/Extensions like Batarang and ng-inspector. This is the newest one, and as the name suggests, it allows you to inspect your application's scopes.

Upvotes: 1

Related Questions