gpt4 book ai didi

javascript - 我如何从 javascript 调用 angularjs 函数?

转载 作者:太空宇宙 更新时间:2023-11-04 16:00:19 24 4
gpt4 key购买 nike

我想从 JavaScript 调用我的 AngularJs 函数

JavaScript

function loadData1() {
var dropdown = document.getElementById("dropdown");
var a = dropdown.options[dropdown.selectedIndex].value;
if (a=="organisationUnits") {
getorganisationUnits();
}
}

AngularJs

var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
//angular.element('#myCtrl').scope().getorganisationUnits();
$scope.getorganisationUnits = function () {
window.alert("Show data");
}
});

HTML

<div ng-app="myApp" ng-controller="myCtrl" id="content">
<select id="dropdown">
<option value="selected"> Please Select Option</option>
<option value="organisationUnits"> Organisation Units</option>
</select>
<input type="button" value="Go" id="getall_go" onclick="loadData1()"></input>
</div>

最佳答案

这是如何以 Angular 方式做到的

var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.load = function() {
console.log("Dropdown value : " + $scope.drop);
if ($scope.drop === "organisationUnits")
console.log("Show data");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl" id="content">
<select id="dropdown" ng-model="drop">
<option value="selected">Please Select Option</option>
<option value="organisationUnits">Organisation Units</option>
</select>

<input type="button" value="Go" id="getall_go" ng-click="load()" />
</div>

关于javascript - 我如何从 javascript 调用 angularjs 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42156906/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com