如何在控制台获取到某个元素的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();

相关文章:

  • 2021-12-11
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
  • 2022-01-01
猜你喜欢
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
相关资源
相似解决方案