[英]How can I console.log expression in AngularJS?
As a new "Angularian", I have this: 作为新的“ Angularian”,我有:
<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)? 但是我想知道,无论我在表达式(ng-model)中键入什么内容,如何都可以console.log?
(eg if I type "Soylent Green is people" in the text field I want to see it in Chrome's Inspector window) (例如,如果在文本字段中输入“ Soylent Green is people”,我想在Chrome的“检查器”窗口中看到它)
You can use console.log($scope.hello);
您可以使用console.log($scope.hello);
inside your controller. 在您的控制器内部。
I suggest you to take a look about Addons/Extensions like Batarang and ng-inspector. 我建议您看一下Batarang和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 在输入标签中使用ng-change指令,例如
<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/ https://jsfiddle.net/walioulislam/wpjwavrc/
您有一个用于此应用程序的控制器,如果您不了解控制器,则可以阅读w3schools中的文档。可以在控制器内部执行console.log($scope.hello)
。默认情况下,您在HTML中定义的每个变量都在其中$ scope对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.