控制台获取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();

posted @ 2016-02-02 20:34  Darren Ji  阅读(1442)  评论(0编辑  收藏  举报

我的公众号:新语新世界,欢迎关注。