Hi,
I want to call AngularJS function such as $scope.CStoJS(text) from Winfrom Application's EO.WebControl.
I already searched this problem below.
http://stackoverflow.com/questions/25031979/using-web-browser-control-with-angularjsBut I don't understand how to fix this problem.
CS code :
public Form1()
{
InitializeComponent();
webView1.RegisterJSExtensionFunction("testCallback", new EO.WebBrowser.JSExtInvokeHandler(JStoCS));
webControl1.WebView.Url = @"http://127.0.0.1:9876/index.html#/test";
}
void JStoCS(object sender, EO.WebBrowser.JSExtInvokeArgs e)
{
string textFromJS1 = e.Arguments[0] as string;
string textFromJS2 = e.Arguments[1] as string;
MessageBox.Show("This message from JS " + textFromJS1 + " " + textFromJS2);
}
private void button1_Click(object sender, EventArgs e)
{
webView1.EvalScript("alert('hi');");
webView1.EvalScript("CStoJSPass('This message from CS.');");
}
JS Code :
angularapp.controller('testCtrl', function($scope){
$scope.sampleText = "This is a sample page.";
$scope.btnClickTest = function()
{
$scope.JStoCS();
};
$scope.CStoJS = function(text)
{
alert("CStoJS 1");
$scope.$apply(function ()
{
alert("CStoJS");
$scope.TextCallback = text;
});
alert("CStoJS 2");
};
$scope.JStoCS = function()
{
alert("JStoCS");
testCallback("test string 1", "test string 2");
};
});
function CStoJSPass(data)
{
alert("CStoJSPass 1");
var dom_el = document.querySelector('[ng-controller="testCtrl"]')
alert("CStoJSPass 2");
var ng_el = angular.element(dom_el);
alert("CStoJSPass 3");
var ng_el_scope = ng_el.scope();
alert("CStoJSPass 4");
var test = ng_el_scope.CStoJS(data);
alert("CStoJSPass 5");
}
Result :
If I click the button on C# UI.
EO.Browser alerts 'Hi', 'CStoJSPass 1', 'CStoJSPass 2', 'CStoJSPass 3', 'CStoJSPass 4'.
But alert("CStoJS 1"); and alert("CStoJSPass 5"); never occur.
Please give me some advice...