控制台获取AngularJS某个元素的Scope

如何在控制台获取到某个元素的Scope呢?

假设,页面元素为:

<label>Name:</label>
<input type="text" ng-model="yourName" placeholder="Enter a name here">
<h1>{{yourName}}</h1>


→ 选择input元素

→ 在控制台输入"$0",显示如下:

<input type="text" ng-model="yourName" placeholder="Enter a name here" class="ng-valid ng-dirty">

→ 在控制台输入"angular.element($0).scope()"

Scope {$id: "006", $$childTail:null, $$childHead: null, $$prevSibling: null, $$nextSibling:null...}

→ 给Scope的变量赋值

var $scope = angular.element($0).scope();
$scope.yourName = "";
$scope.apply();

原文地址:https://www.cnblogs.com/darrenji/p/5178456.html