Accessing "Crowd-entity-annotation" output results - amazon-sagemaker

I want to access the data of crowd-entity-annotation before it submitting. So how can i do that using Javascript?
I have used the following code. But it's not working.
<script>
document.querySelector('crowd-entity-annotation').onsubmit = function(e) {
var b= document.querySelector('crowd-entity-annotation').value.entities;
alert(b);
}
</script>

Related

Reading JSON from file in AngularJS

I am able to read the json content from file in chrome app but i want the returned json content in $scope.somevar. If i try to initialize $scope.somevar inside method, it goes out of scope.
SearchApp.controller("MyTagsApp", function($scope) {
var myFile = '';
chrome.runtime.getPackageDirectoryEntry(function(root) {
root.getFile("MY_FILE.json", {}, function(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
myFile = JSON.parse(this.result);
$scope.somevar = JSON.parse(this.result);
console.log(myFile);
});
});
});
console.log($scope.somevar); });
the last line returns undefined. Being new to the angular technology, i am unable to understand where the issue is.
I am also trying to display the content on HTML page
<ul ng-repeat="i in somevar | filter: searchKeyword">
<li>{{i.items.name}}</li>
</ul>
No Response.
console.log($scope.somevar);
on the last line is executed earlier so the $scope.somevar is not initialized yet. Why are you trying to dump the contents anyway? The JSON content will be eventually accessible in the scope. If you need to do something with that result do it inside the anonymous function.

Displaying data from Firebase onto HTML Webpage

I am able to pull data from firebase and show it in the browser console, but how do I actually display it as text on a webpage?
Here's the code I have now:
<script>
var ref = new Firebase("https://datatest-104.firebaseio.com");
ref.orderByChild("location").equalTo("United States").on("child_added", function(snapshot) {
console.log(snapshot.key());
});
//My code that I'm trying:
document.write(snapshot.key());
</script>
I am trying to use document.write(snapshot.key()); but am not sure how it works.
Put document.write(snapshot.key());into the function instead of out of it:
ref.orderByChild("location").equalTo("United States").on("child_added", function(snapshot) {
document.write(snapshot.key());
});
Then, the snapshotwill be defined, so it'll write onto the page.

why factory don't work properly between the directives?

I make two directives .To communicate between two directives I used a factory .
but it not work properly ..I want to delete my text when I press delete button ..I take factory to do my task but it not working .I also try to take service .it also don't help
here is my code
http://plnkr.co/edit/Yenmira9J9XpjscQzRoX?p=preview
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body ng-app="app">
<a></a>
<b></b>
<script>
angular.module('app',[]).directive('a',function(){
return {
restrict :'E',
scope:{},
templateUrl:'a.html',
controller:'ts',
controllerAs:'vm'
}
}).controller('ts',function(sharedService){
var vm=this;
vm.delete=function(){
alert('--');
sharedService.deletepro();
}
}).directive('b',function(){
return {
restrict :'E',
scope:{},
templateUrl:'b.html',
controller:'bb',
controllerAs:'vm'
}
}).controller('bb',function(sharedService){
var pm=this;
pm.message= sharedService.sendData();
}).factory('sharedService', function() {
var data = {};
function deletepro(){
data = {};
}
function sendData(){
var obj = {name:"pQr"};
data = obj;
return data;
}
return {
sendData: sendData,
deletepro: deletepro
};
});
</script>
</body>
</html>
After your controller is first initialized, data and vm.message reference the same object, but when you run deletepro then data references a new object, but vm.message still references the old one.
If you want to pass data in this way, you must never replace data with a new object (otherwise, controllers will have to get the new object again).
Instead of data = {};, try data.name = '';
It looks like you're expecting that it will update because data is a shared reference. But you are resetting it to {}, which breaks the reference. You instead need to modify it:
function deletepro(){
for(var prop in data){
delete data[prop];
}
}
Also, keep in mind a and b are both real html tags, not sure if there are any issues ovewriting the standard ,

ng-repeat not printing resp.items from cloudendpoint on webpage

I'm new to angularjs. I'm working on a web application using angularjs and cloud endpoints. I'm getting the response from endpoint and I can see that in Console.log also. but when I'm trying to print that response it's not working. I'm not getting what's going wrong. Can anyone fix this?
Here's my code.
HTML Page
<div ng-repeat="lister in lists">
</div><h2>{{lister.title}}</h2>
</div>
AngularJs Code
<script>
function init() {
window.init();
}
</script>
<script>
var app = angular.module('list',[]);
app.controller('listCtrl',function($scope,$window){
$window.init= function() {
$scope.loader();
};
$scope.loader= function(){
gapi.client.load('MyEndPoint', 'v1', function(){
gapi.client.MyEndPoint.MyMethod1({
'latitude':'24.5555','longitude':'45.55555'
}).execute(function(resp) {
$window.console.log(resp);
$scope.lists = resp.items;
});
}, 'https://MyEndpointURL.appspot.com/_ah/api');
};
</script>

Can I pass a global var to an underscore view?

I wonder if possible to do pass a global variable when rendering a template. Basically I get this variable each time I call a controller, so it looks like this:
window.myVar = 0;
//this var will change in a given moment when I make a request to the server.. so:
//into the render method of my view, I have something like this:
var template = _.template($("#myTemplate").html(), { varIwantToPass : myVar } );
this.$el.html(template);
this way I can access it into the template with something like this:
<%= varIwantToPass.get('myVar') %>
if this possible?; and also, each time a render the view, this code will excute again and update the value?
Yes, except you template has to be
<%= varIwantToPass %>
and pass variable as window.myVar so you would not accidentally replace it
And yes it will update after each render if you pass the variable each time
Working example:
Html:
<script id="myTemplate" type="text/html">
<%= varIwantToPass%>
</script>
<div></div>
JS:
window.myVar = 'a';
var templateHtml = $("#myTemplate").html()
var render = function () {
var template = _.template(templateHtml, { varIwantToPass : window.myVar } );
return template;
}
$('div').html(render());
window.myVar = 'b'; //change variable
setTimeout(function() {
$('div').html(render());
}, 1000)
http://jsfiddle.net/omynhL1d/
However I would advocate on not using global variable and instead saving it somewhere in your backbone view or even better a model and then render by listening on that model change event

Resources