I downloaded the ember starter kit and want to show a simple REST API data to see how Ember works.
From videos and tutorials I found that there is a model hook that can be used to inject data.
So I did the following:
App.Router = Ember.Router.extend({
model: function ({
return $.getJSON("https://api.foursquare.com/v2/users/self?oauth_token=TOKENHERE&v=20130723");
}),
root: Ember.Route.extend({
index: Ember.Route.extend({
route: '/'
})
})
})
And added the following in my index.html
<script type="text/x-handlebars" data-template-name="application">
{{title}}
</script>
However, this didn't work. When I go to index.html I don't see anything there. Additionally, under Network tab of Inspect Element, I don't see any network requests being made to the REST API.
What am I doing wrong? Also, for sample purpose I would simply like to have a data.json json file that will contain some json data. However, I read that Ember lacks support to read a file, thats why I'm trying a sample rest api provided by foursquare.
Is there a way to read a json file using ember? I'm running this simply on my browser without a server.
That looks like it should work. Here is an example using a different API but using the same structure:
JavaScript:
App = Ember.Application.create();
App.Router.map(function() {
// put your routes here
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return $.getJSON("https://api.github.com/repos/emberjs/ember.js/stats/contributors");
}
});
Templates:
<script type="text/x-handlebars">
<h2>Welcome to Ember.js</h2>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
Ember.js repository contributors
<ul>
{{#each user in controller}}
<li>{{user.author.login}}</li>
{{/each}}
</ul>
</script>
JSBin example
Related
Not sure if this a Sails.js issue or me missing something implementing axios. I am trying to follow this basic example from axios docs here.
I am referencing the axios library via the CDN URL.
new Vue({
el: '#app',
data () {
return {
info: []
}
},
mounted () {
axios
.get('https://api.coindesk.com/v1/bpi/currentprice.json')
.then(response => (this.info = response))
}
})
<div id="app">{{ info }}</div>
All I see inside the <div id="app"> is []. The call to the API is successful as evidenced by console.log(response) but the div does not update.
Tried changing mounted to created with no luck.
Am I missing additional setup/configuration?
After much digging, discovered that Sails.js uses something called parasails which does auto-magic hookup for vue.js. Essentially, I moved my code to the parasails created javascript file and everything works as expected.
Looks like vue app created in my js file was overridden by the objects created in the js file created via parasails
I'm trying to integrate a Braintree Payments drop-in into an Ionic mobile app. Based on the Braintree documentation and some code examples i was able to find online, the following code is what I've managed to come up with so far but it doesn't seem to work:
controller.js
.controller('CheckoutForm', function($scope, $window) {
$scope.clientToken = "<token generated by the server>"
$scope.renderCheckout = function() {
braintree.setup($scope.clientToken, "dropin", {
container: "payment-form"
});
}
})
template.html
<div>
Payment details:
<form id="checkout">
<div id="payment-form" onLoad="renderCheckout()"></div>
</form>
</div>
I also included the following line in the index.html:
<script src="https://js.braintreegateway.com/js/braintree-2.23.0.min.js"></script>
I'm quite new to Ionic and HTML5/JS development in general so any help would be much appreciated.
Forget about the onload function. Just do this in your controller.
var clientToken = "eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiIyMTUwYzJiOWYyODdlMmZmMzUyZWQxZmMyMDFiNjY3ZDE5OGNhMjEwNjAyYmYzNzI1NmVmNDIzMWY0Yjg3OGNmfGNyZWF0ZWRfYXQ9MjAxNi0wNC0yOFQwNjoyODo1My43NjM0MjY0MzYrMDAwMFx1MDAyNm1lcmNoYW50X2lkPTM0OHBrOWNnZjNiZ3l3MmJcdTAwMjZwdWJsaWNfa2V5PTJuMjQ3ZHY4OWJxOXZtcHIiLCJjb25maWdVcmwiOiJodHRwczovL2FwaS5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tOjQ0My9tZXJjaGFudHMvMzQ4cGs5Y2dmM2JneXcyYi9jbGllbnRfYXBpL3YxL2NvbmZpZ3VyYXRpb24iLCJjaGFsbGVuZ2VzIjpbXSwiZW52aXJvbm1lbnQiOiJzYW5kYm94IiwiY2xpZW50QXBpVXJsIjoiaHR0cHM6Ly9hcGkuc2FuZGJveC5icmFpbnRyZWVnYXRld2F5LmNvbTo0NDMvbWVyY2hhbnRzLzM0OHBrOWNnZjNiZ3l3MmIvY2xpZW50X2FwaSIsImFzc2V0c1VybCI6Imh0dHBzOi8vYXNzZXRzLmJyYWludHJlZWdhdGV3YXkuY29tIiwiYXV0aFVybCI6Imh0dHBzOi8vYXV0aC52ZW5tby5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tIiwiYW5hbHl0aWNzIjp7InVybCI6Imh0dHBzOi8vY2xpZW50LWFuYWx5dGljcy5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tLzM0OHBrOWNnZjNiZ3l3MmIifSwidGhyZWVEU2VjdXJlRW5hYmxlZCI6dHJ1ZSwicGF5cGFsRW5hYmxlZCI6dHJ1ZSwicGF5cGFsIjp7ImRpc3BsYXlOYW1lIjoiQWNtZSBXaWRnZXRzLCBMdGQuIChTYW5kYm94KSIsImNsaWVudElkIjpudWxsLCJwcml2YWN5VXJsIjoiaHR0cDovL2V4YW1wbGUuY29tL3BwIiwidXNlckFncmVlbWVudFVybCI6Imh0dHA6Ly9leGFtcGxlLmNvbS90b3MiLCJiYXNlVXJsIjoiaHR0cHM6Ly9hc3NldHMuYnJhaW50cmVlZ2F0ZXdheS5jb20iLCJhc3NldHNVcmwiOiJodHRwczovL2NoZWNrb3V0LnBheXBhbC5jb20iLCJkaXJlY3RCYXNlVXJsIjpudWxsLCJhbGxvd0h0dHAiOnRydWUsImVudmlyb25tZW50Tm9OZXR3b3JrIjp0cnVlLCJlbnZpcm9ubWVudCI6Im9mZmxpbmUiLCJ1bnZldHRlZE1lcmNoYW50IjpmYWxzZSwiYnJhaW50cmVlQ2xpZW50SWQiOiJtYXN0ZXJjbGllbnQzIiwiYmlsbGluZ0FncmVlbWVudHNFbmFibGVkIjp0cnVlLCJtZXJjaGFudEFjY291bnRJZCI6ImFjbWV3aWRnZXRzbHRkc2FuZGJveCIsImN1cnJlbmN5SXNvQ29kZSI6IlVTRCJ9LCJjb2luYmFzZUVuYWJsZWQiOmZhbHNlLCJtZXJjaGFudElkIjoiMzQ4cGs5Y2dmM2JneXcyYiIsInZlbm1vIjoib2ZmIn0=";
// Client token above is just for testing and provided by Braintree for testing purposes
braintree.setup(clientToken, "dropin", {
container: "payment-form"
});
Then in your html:
<form id="checkout">
<div id="payment-form"></div>
</form>
For mobile remember to add proper Content security policy and whitelists with the cordova-whitelist-plugin.
Documentation for CSP: https://developers.braintreepayments.com/reference/client-reference/javascript/v2/best-practices#using-braintree.js-with-a-content-security-policy
Documentation for Cordova whitelist plugin:
https://cordova.apache.org/docs/en/latest/guide/appdev/whitelist/index.html
What 'thepio' suggested is for testing only. But proper way might be to generate the Client Token on you server. Then your Ionic app will POST and get the Client Token from your server. And then once payment nonce is generated, you can POST your payment data to your server to process the payment.
Check this sample implementation.
https://github.com/demianborba/braintree-cordova-angular-node
I have used the LinkedIn Javascript API calls in my html page. I can see the "Sign In With LinkedIn" button . In "onLinkedInLoad" function calling the "IN.Event.on("IN", "auth", onLinkedInAuth);" is not firing. I have an alert message 'call2' in my code and its also not calling.
Basically I want to read a company updates and bind into a div. In Browser console I am getting the below URL and profile's response. There is no other request in browser console.
https://api.linkedin.com/v1/people::(~):(id,first-name,last-name,headline,picture-url)
I followed all the instructions in LinkedIn document before doing this to consume a company update.
I have a company page and with an update.
I have created an app and use that api key only in js function call.
In LinkedIn REST Console I can see my update.
Do I miss anything ? Thanks.
I use the actual api key and company id at my end.
See my code :
<html>
<head>
<title>
LinkedIn
</title>
<script type="text/javascript" src="https://platform.linkedin.com/in.js">
api_key: 0000000000000
onLoad: onLinkedInLoad
authorize: true
</script>
<script type="text/javascript">
function onLinkedInLoad() {
alert('call');
IN.Event.on("IN", "auth", onLinkedInAuth);
}
function onLinkedInAuth() {
alert('call2');
IN.API.Raw("/companies/000000/updates")
.method("GET")
.result(function(res) {
document.write(JSON.stringify(res));});
}
</script>
</head>
<body>
<script type="IN/Login">
</script>
</body>
</html>
I have used IN.User.authorize(onLinkedInAuth) instead of IN.Event.on("IN", "auth", onLinkedInAuth) for authorization and worked.
I want to use the addthis custom services for my project. I tried following code:
<script type="text/javascript">
var addthis_config = {
services_custom: [{
name: "AddThis",
url: "http://addthis.com/bookmark.php?url=http://purab.com&title=purabtitle",
icon: "http://addthis.com/images/addthis32.gif"
}]
}
</script>
<a class="addthis_button_addthis.com 32x32"></a>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5281ee5c7439355a"></script>
<!-- AddThis Button END -->
I got following code snippet from following URL:
Addthis Custom Services API
But code is not working. I found following article which talks about same.
http://support.addthis.com/customer/portal/questions/1378256-custom-service?t=89322
I asked question to there support but I did not got any answer yet.
Anybody worked on addthis custom services
So I copied your example and got it to work by replacing http://purab.com with {{url}} and purabtitle with {{title}} in the url property so it should look like this:
url: "http://addthis.com/bookmark.php?url={{url}}&title={{title}}",
Give that a try and let me know if it's still not working.
I'm having an issue connecting to Facebook through the Javascript Client Library in Adobe AIR. It works fine in the browser but in Adobe AIR it seems to not be able to find the Facebook functions. Here is some code I copied from the Facebook website: (Oh and I have the xd_receiver.htm file in the correct path too)
<textarea style="width: 1000px; height: 300px;" id="_traceTextBox">
</textarea>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
//
var api = FB.Facebook.apiClient;
// require user to login
api.requireLogin(function(exception){
FB.FBDebug.logLevel=1;
FB.FBDebug.dump("Current user id is " + api.get_session().uid);
// Get friends list
//5-14-09: this code below is broken, correct code follows
//api.friends_get(null, function(result){
// Debug.dump(result, 'friendsResult from non-batch execution ');
// });
api.friends_get(new Array(), function(result, exception){
FB.FBDebug.dump(result, 'friendsResult from non-batch execution ');
});
});
});
//]]>
</script>
It's not that simple actually man, the problem with loading external script files from the application sandbox is that it's not supported. Technically, by using iframes, you should be able to do this and it works but it's still impossible to use XFBML in the root document after from my experience. After two days of trial and error, the easiest way to do use Facebook Connect in an html/ajax adobe air application is to download the actionscript library and include it as such:
<script type="application/x-shockwave-flash" src="lib/facebook.swf"></script>
<script type="text/javascript">
var FB = window.runtime.com.facebook;
var fb = new FB.Facebook();
var session = new FB.utils.DesktopSessionHelper();
//etc...
</script>
then just refer to the documentation. my only problem now it that I still haven't found an efficient enough way of using XFBML in adobe air, simply adding the facebook namespace to the html tag doesn't do the trick unfortunately. If any knows, please do share thanks
you also need to change xml namespace (main html tag) to this:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xml:lang="en-gb" lang="en-gb">