I want to load a JSON file and draw a table with angular.
It works when i use this line :
$http.get("datatest3.txt")
But once I use the url instead "http://www.floatrates.com/daily/eur.json", while the content is the exact same JSON data,
it does not work.
Does someone know why ?
Related
Angularjs How can i post/put data into local json file?
To get data, i do:
App.factory('serv', ['$http', function ($http) {
var data = {};
db.getdata = function(){
return $http.get('data/album.json');
}
return data;
}])
I dont know how to do for POST , PUT and DELETE.
Is it possible?
You can try this useful Angular API : https://github.com/mgonto/restangular
if you want to manage data saved in a json file then you can use this JSON server : https://github.com/typicode/json-server
You can write to local files with JavaScript using the HTML5 file system API. Check here: http://caniuse.com/#feat=filesystem to see if it's supported where you need to use it.
If you are able to use it, then you would simply write out a new JSON file in its entirety when you want to persist your data. You can read about the file system API here: https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Introduction
If your needs are more than just a simple JSON document you might want to check out indexeddb as well.
I want to load a modified .tpl file vtigercrm\layouts\vlayout\modules\Vtiger\ListViewContents.tpl to a .php file from which I get HTML data after using AJAX and javascript . It's something feasible?
Im assuming that you want to view that template in the DetailView. In that case you can make a widget in module/Vtiger/models/DetailView.php in getWidget(). Just copy paste and change. The link you give here should go to a function in /module/Vtiger/views/Detail.php.
you should add your new function in the constructor.
$this->exposeMethod('Yourfunctionname');
Here you can copy any function and change it. you need to feed your variables to smarty with :
$viewer->assign('SMARTYVARNAME', $phpVar);
to fill the template. And finally you need to referance the template.
echo $viewer->view('tplname.tpl', $moduleName, 'true');
im not able to comment yet so i hope this is enough.
I'm a beginner with Angular and I want to make a ng-repeat of images in a folder. All my images have different names so I don't see how I can make a ngSrc for all the images.
Hope I am clear enough.
You can try something like this.
Grab all the image filenames and store it in a javascript array with in the javascript for your controller. I'm assuming you would be doing this on your server side and return JSON back to client through an API or Service.
In you controller, the result would look like this.
$scope.myImages = ["image1.jpg", "image2.jpg"];
You have many options now. One way is to write a little function that returns the full path and call it from ng-src.
$scope.getImagePath = function(imageName) {
return "http://yoursite/location/" + imageName;
};
<div ng-repeat="myImage in myImages">
<img ng-src="{{getImagePath(myImage)}}"/>
</div>
Similar post here
Try to give some code snippets using JSFiddle or Plunker next time as it would clearly show what you are trying to do.
[Update]
I don't know what language/framework you are using on the server side but to get all the files in a directory is very easy. Below are examples using node.js and C# respectively.
http://www.csharp-examples.net/get-files-from-directory/
How do you get a list of the names of all files present in a directory in Node.js?
If you are using ASP.NET WEB API, then just return the array back from the Get method in your API Controller, and then call that API from Angular directly.
There are tons of examples on how to do this. Just do some research and you should be fine.
I have some problems with jsonp and AngularJs
I one page, i have to make about 15 json calls, each one by jsonp
My calls look like this :
$http.jsonp("http://www.example.com/feed1.json?callback=JSON_CALLBACK1")
And in my json feed, the data is wrapped by JSON_CALLBACK1
But i always obtain this error :
Uncaught ReferenceError: JSON_CALLBACK1 is not defined
Now i noticed in the network tab in the Google Chrome inspector that the call was :
http://www.example.com/feed1.json?callback=angular.callbacks._0
So i changed my json file, to wrap data with angular.callbacks._0(); instead, and it worked for this one, but it did not work for all my json
I started wraping all my jsons with angular.callbacks._1, angular.callbacks._2, angular.callbacks._3 ... byt i noticed that the number isn't always the same ? and if the number is a two digits, it doesn't work. For example, i tryed angular.callbacks._15, and i always obtain this error
Uncaught ReferenceError: angular.callbacks._15 is not defined
So is there a way to fix all those jsonp problems once for all with AngularJs ?
Thanks
The callback=angular.callbacks._123 parameter is an information for the server that the client (browser) expects the response to be wrapped inside a function named angular.callbacks._123 like so:
angular.callbacks._123({
"key": "value"
});
You should change your server code to inspect the parameter value and if present use it as the wrapping function name.
You can find more details in wikipedia.
I am working with fabric.js inside of backbone.js, and trying to figure out how to load a Base64 image using fabric's command:
fabric.Image.fromURL( 'url', function(img)....
It works fine when I plug in a static url, like:
fabric.Image.fromURL('http://www.domain.com/image.jpg', function(img) {
img.set({ left: ui.offset.left, top: ui.offset.top});
canvas.add(img);
});
but I cannot get a Base64 image to load successfully. How I am I supposed to solve this problem?
All of the above answers are correct. But without an example, the answers aren't obvious.
fabric.Image.fromURL('data:image/png;base64,iVBORw0KGgo....', function(img) {
img.set({ left: ui.offset.left, top: ui.offset.top});
canvas.add(img);
});
Try: data:image/jpeg;base64,"+url. If this doesn't work then maybe your base64 is broken or you might need to tweak the base64 to unit8 conversion technique provided here and add the image data to the image object placed inside the canvas.
Data URI
Make sure your data url is according to the following format:
data:[< mediatype >][;base64],< data >
MDN
<data> above should be a valid base64 string.
If you want to test whether it's fabric that's not rendering the url or url isn't correct, try to open the whole data url in browser, browser will render the image if it's a correct data url.
fabric should just work fine for a base64 data url as it works for http image address.