在angularjs中通过angular.element(dom).scope()可以拿到某个dom元素关联的作用域,从而可以访问$scope中的属性和方法。但是在ng-controller函数之外修改$scope中的数据,angular的$scope是不会自动刷新的,即双向绑定特性失效。
<html>
<head>
<script src="angular-1.3.15.js"></script>
<script>
var app = angular.module('app', []);
app.controller("myController",function($scope){
$scope.buttonAdisable = true;
$scope.buttonBdisable = true;
//让a按钮可用
$scope.enableA=function(){
$scope.buttonAdisable=false;
};
});
// 启动模块
angular.element(document).ready(function() {
angular.bootstrap(document.getElementById("root_div"),["app"]);
});
// 让b按钮可用
function enableB()
{
var scope = angular.element(document.getElementById('b')).scope();
scope.buttonBdisable=false;
}
</script>
</head>
<body>
<div id="root_div