在Angular外部使用js调用Angular控制器中提供的函数方法或变量

如果觉得文章不错,请关注公众号:Java开发高级进阶 ,感谢对博主的支持!

博主在流程设计器中遇到的问题,在此记录一下

流程设计器使用Angular整合的,现遇到一个bug解决办法需要在html中添加onmousedown方法,然后在js中调用Angular里面写好的关闭弹框方法,现简化的代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<div class="modal" ng-controller="KisBpmAssignmentPopupCtrl" onmousedown="checkM(event)">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" ng-click="close()">&times;</button>
<h2 translate>PROPERTY.ASSIGNMENT.TITLE</h2>
</div>
<div class="modal-body">
<div class="row row-no-gutter">
<div class="form-group">
<label for="groupField">{{'PROPERTY.ASSIGNMENT.CANDIDATE_GROUPS' | translate}}</label>
<div id="groupField" ng-repeat="candidateGroup in assignment.candidateGroups">

<ui-select ng-model="candidateGroup.value" theme="bootstrap">
<ui-select-match placeholder="选择一个岗位">{{$select.selected.name}}</ui-select-match>
<ui-select-choices ui-disable-choice="hasSelected(item)" repeat="item in rolelist | filter: $select.search">
<div ng-bind-html="item.name | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>

<i class="glyphicon glyphicon-minus clickable-property" ng-click="removeCandidateGroupValue($index)"></i>
<i ng-if="$index == (assignment.candidateGroups.length - 1)" class="glyphicon glyphicon-plus clickable-property" ng-click="addCandidateGroupValue($index)"></i>
</div>
<div ng-if="assignment.candidateGroups.length== 0">
<i class="glyphicon glyphicon-plus clickable-property" ng-click="addCandidateGroupValue($index)"></i>
</div>

</div>
</div>

</div>
<div class="modal-footer">
<button ng-click="close()" class="btn btn-primary" translate>ACTION.CANCEL</button>
<button ng-click="save()" class="btn btn-primary" translate>ACTION.SAVE</button>
</div>
</div>
</div>
</div>

<script type="application/javascript">
function checkM(event){
console.log(event);
if((event.clientX < 314.4 || event.clientX > 916) || (event.clientY < 27 || event.clientY > 345)){
console.log(" good news !");
//通过controller来获取Angular应用
var appElement = document.querySelector('[ng-controller=KisBpmAssignmentPopupCtrl]');
//获取$scope变量
var $scope = angular.element(appElement).scope();
// 调用close方法
$scope.close();
// 同步到Angular控制器中
$scope.$apply();
}
}
</script>

参考的博客:https://www.cnblogs.com/qubernet/p/5222494.html