繁体   English   中英

如何从JavaScript调用angularjs函数?

[英]How do i call angularjs function from javascript?

我想从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>

这是如何以有角度的方式做到这一点

 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> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM