my first message :)
well, i am trying to write a weather Spa with angular.
as part of the model , i need to grab the location Lat and Lon so im using google geocoding api.
after using $resource.get i am successfully getting the object from google but cant access it.
here is my code :
weatherApp.controller('forecastController'['$scope','location','$resource',function($scope,location,$resource){
$scope.toGoogle = location.toGoogle;
$scope.resource = $resource('http://maps.googleapis.com/maps/api/geocode/json?');
$scope.georesult = $scope.resource.get({address:$scope.toGoogle,Key:"somekey"})
console.log(angular.fromJson($scope.georesult));
}]);
$scope.toGoogle is just a var holding the address which needs to be translated into x and y
the thing is - i am getting a response with the object i was expected, but when i am trying to access it with:
console.log(angular.fromJson($scope.georesult.results[0].geometry.location.lat));
I am getting "TypeError: Cannot read property '0' of undefined"
(Please note that i have already transformed the Json into regular object with Angular.fromJson);
Any suggestions ? thanks in advance.
Related
Here is the api link:
http://api.aladhan.com/v1/timingsByCity?city=Dubai&country=United%20Arab%20Emirates&method=8
<Text>{responseMsg.code}</Text>
<Text>{responseMsg.status}</Text>
The above lines are working.
I am able to fetch data from this API like, code, status but I am unable to fetch prayer times from this API. I don't know how to write that line to fetch prayer times from this API.
<Text>{(responseMsg.data || []).map(time => time.timings.Fajr)}</Text>
<Text>{(responseMsg.data || []).map(time => time.timings.Dhuhr)}</Text>
I am getting the following error TypeError: undefined is not an object (evaluating '(responseMsg.data || {}).timings.Fajr')
You should directly access the timings because data field is object and not an array. What you have to write is :
<Text>{(responseMsg.data || {}).timings.Fajr}</Text>
.Map on responseMsg.data won't work as data is an object. Map is a function on arrays not object.
I know that my answer is sooo late ,since i was searching for the same issue
the trick is that in the output json nested objects,ther is another child data object
so to access prayers times :
fajr=response.data.data.timings.fajr
yes data.data
timezone=response.data.data.meta.timezone
hijriDay=response.data.data.date.hijri.day
hijriMonth=response.data.data.date.hijri.month.en
hijriYear=response.data.data.date.hijri.year
Here im having data Like
""{\"resultStatus\":\"success\",\"message\":\"AUTH-040010: Successfully logout user\",\"language\":\"en\",\"region\":\"us\",\"securityToken\":\"C29F32A5-CF46-4CE8-B1DF-4FBC207ABA19|13|1550120060454\",\"userName\":\"John\",\"organisationId\":1,\"isSearch\":false,\"productId\":1,\"productKey\":\"fAyhhy455Hh4d52c\",\"menuKey\":\"LOG\",\"pageDto\":{\"selectedPage\":1,\"totalCount\":0,\"recodsPerPage\":25},\"menuMasterDtoList\":{},\"validated\":true}Redirectdata=https://192.168.10.19:8089/iauth/access/login?productId=1&productKey=f8cc80d…a24d52c&redirectUrl=http://172.16.1.135:458/Enquiry/openenquiries&Message= Success&MessageType=1""
in this Url How can i get Redirectdata Url
JSON.stringify(d.data) By using this i convert that string in Json
But
JSON.stringify(d.data.Redirectdata)
This is Giving me undefind
Please help me how can i get Redirectdata Url
It because Redirectdata is not a JSON key its outside of JSON object
I am accessing corporate enterprise service bus endpoint to get data. I have a angular.js app (1.5 version) and using breeze with it to load data from this service. I want to know how I can get a list of unique values on one property. Can someone tell me? Thanks. Below is my code to access data. If i do a .distinct() after select below, that throws error.
getProductBaseInformation(): ng.IPromise<any[]> {
var query = this.breeze.EntityQuery.from("ProductBaseInformation").select("ProductCode");
return this.manager.executeQuery(query);
}
Turns out it cannot be done! :-(
Hy, I have some problems with the Go endpoints and Dart client library.
I use the Go library https://github.com/crhym3/go-endpoints and the dart generator https://github.com/dart-lang/discovery_api_dart_client_generator
The easy examples works fine. But they show never how to use time.Time.
In my project, I have a struct with a field:
Created time.Time `json:"created"`
The output in the explorer looks like this:
"created": "2014-12-08T20:42:54.299127593Z",
When i use it in the dart client library, I get the error
FormatException: Invalid date format 2014-12-08T20:53:56.346129718Z
Should I really format every time fields in the go app (Format Timestamp in outgoing JSON in Golang?)?
My research come to that the dart accept something:
t.Format(time.RFC3339) >> 2014-12-08T20:53:56Z
Second problem, if comment out the Created field or leave it blank. I get a other error:
The null object does not have a method 'map'.
NoSuchMethodError: method not found: 'map' Receiver: null Arguments:
[Closure: (dynamic) => dynamic]
But I can't figure it out which object is null. I'm not sure if I'm using the Dart client correct
import 'package:http/browser_client.dart' as http;
...
var nameValue = querySelector('#name').value;
var json = {'name':nameValue};
LaylistApi api = new LaylistApi(new http.BrowserClient());
api.create(new NewLayListReq.fromJson(json)).then((LayList l) {
print(l);
}).catchError((e) {
querySelector('#err-message').innerHtml=e.toString();
});
Does anyone know of a larger project on github with Go endpoint and Dart?
Thanks for any advice
UPDATE[2014-12-11]:
I fixed the
NoSuchMethodError
with the correct discovery url https://constant-wonder-789.appspot.com/_ah/api/discovery/v1/apis/greeting/v1/rest
The problem with the time FormatExcetion still open, but I'm one step further. If i create a new item, it doesn' work. But if I load the items from the datastore and send it back, this works.
I guess this can be fixed with implementing Marshaler interface, thanks Alex. I will update my source soon.
See my example:
http://constant-wonder-789.appspot.com/
The full source code:
https://github.com/cloosli/greeting-example
Restangular.one('suppliers', 'me').getList('websites').then(
(data) ->
$scope.websites = data
$scope.websites.patch()
)
I'm just trying this for a quick test.
So the api call on /suppliers/me/websites returns an array but when I try to patch from the Restangular object it sends the data splitted as you can see below.
[{"0":"h","1":"t","2":"t","3":"p","4":":","5":"/","6":"/","7":"w","8":"w","9":"w","10":".","11":"p","12":"f","13":"c","14":"o","15":"n","16":"c","17":"e","18":"p","19":"t","20":".","21":"c","22":"o","23":"m"}]
I'm new to Angular & Restangular , what am I missing ?
Edit : To be clear, I insta patch for the test but normally I modify the websites array by adding / removing.
It looks as if you're returning a string from your service, whereas a valid JSON response is expected by Restangular.
For example:
[{"website": "http://www.example.com"}, {"website": "http://www.domain.com"}]
EDIT: I just noticed that in your question, you say your service returns an array. Double-check what it does return and make sure that it is valid JSON.
EDIT 2: It seems that Restangular expects not only valid JSON, but also JSON formatted as my code sample above is (ie. [{"key": "value"}] and not ["value"].