I need to call an AngularJS function call from javascript-side.
The below is the function I want to call from javascript.
https://github.com/aws-samples/aws-iot-examples/blob/master/mqttSample/js/app.js
AppController.$inject = ['$scope'];
AppController.prototype.createClient = function() {
var options = {
clientId : this.clientId,
endpoint: this.endpoint.toLowerCase(),
accessKey: this.accessKey,
secretKey: this.secretKey,
regionName: this.regionName
};
var client = this.clients.getClient(options);
if (!client.connected) {
client.connect(options);
}
};
My javascript
<body>
<div id='myid' class="container" ng-app="awsiot.sample" ng-controller="AppController as vm">
....
<div class="form-group">
<button class="btn btn-primary" id='myclick' ng-click="vm.createClient()" >Create Client</button> <-- working! -->
</div>
....
<script>
angular.element('#myid').scope().createClient(); // not working!
</script>
Can you help me?
angular.element. Also controller scope is created during the AngularJS run phase which occurs well after DOMContentLoaded. This looks like an XY Problem. What are you trying to accomplish here? Maybe there is a better way than calling a controller function from outside the AngularJS framework.