Monday, June 20, 2016

Android Webview call Angular controller function.

Since the web is written with AngularJS 1.x, things are working with $scope that it does not look alike simple javascript; anyway, here is how I call a function declared in a controller successfully through Webview.

Android webview:
myWebView.loadUrl("javascript:drvAppDevicePosition('" + mLat + "','" + mLng + "');");


Javascript:
window.drvAppDevicePosition = function(a, b) {      
        $scope.$apply(function() {          
                console.log("Lat:"+a+"; Lng:"+b);
        });      
    };



No comments: