I am trying to call function in controller scope from my java code. After lot of search in Google I found this code to call Js function from Java code but I couldn't call my controller function directly.
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.addJavascriptInterface(jsInterface, "JSInterface");
myWebView.loadUrl("javascript:"+functionName);
Finally I am able to call Js function from Java. Now I want to call my controller function from other function which is not in controller. I tried below code to call AngulrJs controller function from outside.
var scope = angular.element(document.getElementById("messageList")).scope();
scope.$apply(function(){
scope.number = '345';
scope.message = 'Shan';
scope.addItem();
})
But this code resulting below error
Uncaught TypeError: Cannot read property '$apply' of undefined
I tried both $apply and safeApply, not working. I am new to AngularJs and any suggestion will be helpful to me.
HTML code:
<div id="mainContainer" ng-controller="MainCtrl">
<ion-nav-view></ion-nav-view>
</div>
<script id="message.html" type="text/ng-template">
<ion-view title="Message">
<ion-content>
<div id="messageList" ng-controller="MessageCtrl">
<ion-list>
<ion-item ng-repeat="item in items">
{{item.number}} - {{item.message}}!
</ion-item>
</ion-list>
</div>
</ion-content>
</ion-view>
</script>
document.getElementById("messageList")defined?