Welcome Guest Search | Active Topics | Sign In | Register

How EO.WebControl call angularjs function? Options
hjkim
Posted: Monday, December 7, 2015 6:35:19 AM
Rank: Newbie
Groups: Member

Joined: 12/7/2015
Posts: 9
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-angularjs

But 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...
eo_support
Posted: Monday, December 7, 2015 6:17:18 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

This mostly is due to some JavaScript code error in your code. You can use the remote debugger feature to debug your JS code to find out the exact problem:

http://www.essentialobjects.com/doc/webbrowser/advanced/remote_debug.aspx

Thanks!
hjkim
Posted: Thursday, December 10, 2015 6:59:32 AM
Rank: Newbie
Groups: Member

Joined: 12/7/2015
Posts: 9
Thanks!
It solved.
eo_support
Posted: Thursday, December 10, 2015 9:31:59 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Great. Glad to hear that it works for you! Please feel free to let us know if there is anything else.
hjkim
Posted: Friday, December 11, 2015 2:58:14 AM
Rank: Newbie
Groups: Member

Joined: 12/7/2015
Posts: 9
Yes... there is an another issue..
I am trying to test "Accessing JavaScript Object(.NET -> JS)" for passing something such as BMP, XML, JSON.

I know this is not a best way of sending data.

But I have a legacy console component and I don't want to change its data manager protocol.
I just want to modify my c# controller and it relays data from legacy data manager to E.O.WebBrowser control.

I already tested "Accessing JavaScript Object(.NET -> JS)" example code and it works fine.
I wonder if E.O.WebBrowser can receive big data amount of XXmb without error.
And also I want to know it supports thread something or it needs extra C# code for preventing UI thread dead.

If javascript request that data to legacy code it cause cross domain issue(but can be solved), and it is hard to maintain....
I hope E.O.WebBrowser acts like UI Control not need to do something for webserver which is running locally.
eo_support
Posted: Friday, December 11, 2015 1:32:59 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

You should be able to pass large data as well but you can only pass them in simple types. For example, if you have an object with an int field and a string field, you can pass two arguments, one as int, one as string to the JavaScript (as an object array) directly. However you can not pass your a single value of your object. If you wish to pass complex structural data, you can use JSON to encode your data on the .NET side and then use JSON.Parse to parse it back to a JavaScript object on the JavaScript side.

Thanks!
hjkim
Posted: Sunday, December 13, 2015 8:21:10 PM
Rank: Newbie
Groups: Member

Joined: 12/7/2015
Posts: 9
I did't tell the data type.
I am going to pass large data as string inside JSON.
I will test about it.
Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.