I created a sample demo application that has the following html page.
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script>
function alert1(p1) {
alert("P1 is "+p1);
}
</script>
<link type="text/css" rel="stylesheet" href="Sample_JS.css">
<title>Web Application Starter Project</title>
<script type="text/javascript" language="javascript" src="sample_js/sample_js.nocache.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', [])
app.controller('MyController', function ($scope, $window) {
$scope.nameList = [];
$scope.ShowAlert = function () {
$scope.nameList.push($scope.nameFieldContainer);
$window.alert("Hello Angular : "+$scope.nameFieldContainer);
}
});
</script>
</head>
<body>
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
<noscript>
<div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
Your web browser must have JavaScript enabled
in order for this application to display correctly.
</div>
</noscript>
<div ng-app="MyApp" ng-controller="MyController">
<h1>Web Application Starter Project</h1>
<table align="center">
<tr>
<td colspan="2" style="font-weight:bold;">Please enter your name:</td>
</tr>
<tr>
<td data-ng-model="nameFieldContainer" id="nameFieldContainer"></td>
<td id="test" ></td>
<td id="sendButtonContainer" ng-click="ShowAlert()"></td>
</tr>
<tr>
<td> <input type ="text" data-ng-model="nameFieldContainer"> </td>
<td colspan="2" style="color:red;" id="errorLabelContainer"></td>
</tr>
<tr>
<td><input type = "button" name="click" ng-click="ShowAlert()"></td>
</tr>
</table>
<table align="center">
<tr ng-repeat = "name in nameList">
<td colspan="2" style="font-weight:bold;">{{name}}</td>
</tr>
</table>
</div>
</body>
</html>
My gwt controller class as below
package com.google.client;
import com.google.shared.FieldVerifier;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
public class Sample_JS implements EntryPoint {
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";
private final GreetingServiceAsync greetingService = GWT
.create(GreetingService.class);
public void onModuleLoad() {
final Button sendButton = new Button("Add");
final TextBox nameField = new TextBox();
nameField.setText("GWT User");
final Label errorLabel = new Label();
sendButton.addStyleName("sendButton");
RootPanel.get("nameFieldContainer").add(nameField);
RootPanel.get("sendButtonContainer").add(sendButton);
RootPanel.get("errorLabelContainer").add(errorLabel);
nameField.setFocus(true);
nameField.selectAll();
closeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
dialogBox.hide();
sendButton.setEnabled(true);
sendButton.setFocus(true);
}
});
class MyHandler implements ClickHandler, KeyUpHandler {
public void onClick(ClickEvent event) {
MyTestJS.hasPopupBlocker(nameField.getValue());
}
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
sendNameToServer();
}
}
MyHandler handler = new MyHandler();
sendButton.addClickHandler(handler);
nameField.addKeyUpHandler(handler);
}
}
I am trying to call the anularjs function from the underlying js method using the gwt button component, but I cannot.
package com.google.client;
public class MyTestJS {
public static native boolean hasPopupBlocker(String name);
}
How can I call the angularJs ShowAlert () function from gwt (by clicking a button from java code or in another way)? please suggest. any help would be appreciable ...... thanks in advance.
source
share