我想将值传递给android中控制器中的AngularJS方法

时间:2014-08-26 12:00:18

标签: javascript android angularjs angularjs-scope

您好我想将值传递给AngviewJS中控制器中从Webview Controller android定义的方法。我发送我的代码请检查。在此先感谢。

myBrowser = (WebView) findViewById(R.id.mybrowser);
client = new WebChromeClient();
final MyWebClient myJavaScriptInterface = new MyWebClient(this);
myBrowser.addJavascriptInterface(myJavaScriptInterface, "AndroidFunction");
myBrowser.setWebChromeClient(client);
myBrowser.getSettings().setJavaScriptEnabled(true);
myBrowser.loadUrl("file:///android_asset/angularjsandroid.html");

myBrowser.loadUrl("javascript:callFromActivity1(\'" + json+ "\')");

JS代码

function personDetail($scope) {
    $scope.getPersonDetail = function() {
        var jsonString = JSON.stringify($scope.data);
        showAlert(jsonString);
    };

    $scope.updatePersonDetail = function(details){
        AndroidFunction.getJSONData($scope.id); 
    };

    $scope.callFromActivity1 = function(msg) {
        alert(msg);
    };
});

1 个答案:

答案 0 :(得分:0)

是的,确实如此:

var angular_scope = angular.element($("#main_content")).scope();

然后你用它做任何你想做的事