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)?
(eg if I type "Soylent Green is people" in the text field I want to see it in Chrome's Inspector window)
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.
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);
}
您有一个用于此应用程序的控制器,如果您不了解控制器,则可以阅读w3schools中的文档。可以在控制器内部执行console.log($scope.hello)
。默认情况下,您在HTML中定义的每个变量都在其中$ scope对象
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.