My web method returns object 'User' that has a lot of properties.
In my 'OnComplete' function I am receiving those object.
function OnComplete(args) {
var res = $get('WsResult');
debugger;
res.innerHTML = args['Nick'];
}
Question: How can I get values of object properties?
The code above provides me with '[object Object]' text instead of real object value.
Thanks a lot!
You can get these properties the same way you get any other properties:
alert(args.Nick.FullName);
Related
One of my components needs to fetch different data from a property based on a parameter I pass it. The parameterHolder is an Object with keys and parameter is the key name.
{{component-name parameterHolderBinding=parameterHolder parameterValueBinding=parameter}}
I'm trying to loop through it like so
{{#each item in parameterHolder.[{{parameter}}]}}
{{/#each}}
But it's not working. When I try,
{{parameterHolder.keyName}}
I'm getting [Object] which is correct. Could someone please point out the right way do this?
I've managed to get it working by dynamically creating new properties.
In my controller -
parameterUpdatedObserver: function ()
{
var reference = this;
$.each(parameterHolder, function (key, value) {
reference.set('parameterHolderName'+key, value);
});
}.observes('parameterHolder')
And my component -
{{component-name parameterHolderBinding=parameterHolderNameKey parameterValueBinding=parameter}}
I can probably abstract it up one more level using another component. If anyone has a better solution, please do post it.
I'm trying to put together my first CRUD app using AngularJS and Asp.Net Web Api. I have setup the controller with a newMember object:
$scope.newMember = {};
And then call the insert in the factory method as:
dataService.insertMember($scope.newMember);
This calls the method in the dataService:
var _insertMember = function(member) {
return $http.post("/api/clubmembers/", member);
};
which fires the Web Api Post method
public HttpResponseMessage Post([FromBody]PersonViewModel member)
{
//if (_repo.AddClubMember(member) && _repo.Save())
if (_repo.AddClubMember(member) && _repo.Save())
{
return Request.CreateResponse(HttpStatusCode.Created, member);
}
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
I have checked the data in the Angular part of the app and the correct data is passed via $scope.newMember, but when it reaches the Web Api Post method the member parameter is always Null.
If I modify the controller method to the following it passes the data to the Post method as expected:
var testData2 = {
FirstName: $scope.newMember.FirstName,
LastName: $scope.newMember.LastName
};
var a = 1;
dataService.insertMember(testData2);
Is it possible to pass $scope.newMember as the parameter or do I have to fill in the details as of the amended code?
Thanks
Mark
Check your code carefully, I would say (based on your experience described in the question) there will be some typo.
Call with explicit {} - empty object
If you will call your service like this:
dataService.insertMember({}); // just created empty object
you will get instantiated object on your API Post method PersonViewModel member
Call with explicit null or undefined
but in case, that you will call one of these
dataService.insertMember(null);
dataService.insertMember(undefined);
the API Post method will be provided with NULL.
typo (incorrect property name), i.e. undefined
And what that means? that you most likely, somewhere in the call chain used something like this
$scope.newMember ...
...
dataService.insertMember($scope.newMemberXXX);
where newMemberXXX represents any undefined property, resulting in undefined to be passed
If you add FirstName and LastName properties to newMember it should work fine:
$scope.newMember = {};
$scope.newMember.FirstName = "First Name";
$scope.newMember.LastName = "Last Name";
dataService.insertMember($scope.newMember);
Thing is, $scope.newMember has to match the properties and structure of PersonViewModel for the Web Api to be able to match the two types.
Let us know if this works.
I am having issues binding to an object in firebase. I am using AngularFire and the code in my Angular controller looks like this:
var firebaseCourse = new Firebase("https://torid-fire-1683.firebaseio.com/course-header/course-1");
$scope.course = $firebase(firebaseCourse);
This does successfully connect to firebase and return my data. However, when the object is returned, it is embedded in another object like this:
{"-JDlZpk38i9YsSRoH0ce":{"description":"Course Description","name":"Course One"}}
Thus, when I bind to {{course.name}} in my view, it doesn't work, because the properties are embedded inside another object in the object that $scope.course is bound to.
How do I get around this?
What you are seeing is exactly what firebase sends back. So your code is actually working. I believe that all you have to add is :
$scope.course = $firebase(firebaseCourse).$asArray();
If $asArray() still doesn't give you what you want, you can iterate over the object and create and array. So in your view you can do this:
In your view(html) - instead of - {{courses}} ----> {{getCourses(courses)}}
& in you controller
$scope.getCourses = function(courses) {
var array = [];
for(var key in courses) {
array.push(courses[key]);
}
return array;
}
This way you will have an array or courses instead of a nested object. This will not effect the 3 way binding that is provided by angularFire
Hope this helps! Thanks
There are a three public variable
public var objPrintJob:FlexPrintJob;
public var objPrintTemplate:canvas;
Fn1:
objPrintJob = new FlexPrintJob();
if (objPrintJob.start() != true)
{
printCount--;
return;
}
Starting the PrintJob;
Fn2:
Am adding the Object and calling send for the Print
objPrintJob.addObject(objPrintTemplate, FlexPrintJobScaleType.SHOW_ALL);
objPrintJob.send();
During Run
It Throws the Error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.printing::FlexPrintJob/addObject()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\printing\FlexPrintJob.as:252]
at org.dckap.mafcote.views.mediators::WorkAreaMediator/parseXML()[F:\MafcoteMGP\MafcoteMGP\src\org\dckap\mafcote\views\mediators\WorkAreaMediator.as:3243]
at org.dckap.mafcote.views.mediators::WorkAreaMediator/onSaveTemplateWithCredits()[F:\MafcoteMGP\MafcoteMGP\src\org\dckap\mafcote\views\mediators\WorkAreaMediator.as:2896]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:12266]
at org.dckap.mafcote.views::CreditsShowPanel/okButtonClickHandler()[F:\MafcoteMGP\MafcoteMGP\src\org\dckap\mafcote\views\CreditsShowPanel.mxml:41]
at org.dckap.mafcote.views::CreditsShowPanel/__btnOk_click()[F:\MafcoteMGP\MafcoteMGP\src\org\dckap\mafcote\views\CreditsShowPanel.mxml:159]
Need Help For This..
}
This has to be that your objPrintTemplate object is null. The stack trace in your error shows that it's erroring in FlexPrintJob/addObject(), which means it made it into that method but did not complete executing the method. Since the only parameters you're sending to it are your object reference and a constant value, the object must be null.
After your support I found out my solution.
Thank U all.
The object does not seems to be null.
I did one mistake that is i didn't added the object as a child anywhere else.
so the addObject() in print requires the systemManager.
which will be null if i didn't add as a child.
Thank You for your support
I am a Java programmer and need to work on a Flex/ActionScript project right now. I got an example of using ITreeDataDesriptor from Flex 3 Cookbook, but there is one line of actionscript code that's hard for me to understand. I appreciate if someone could explain this a little further.
public function getData(node:Object, model:Object=null):Object
{
if (node is Office) {
return {children:{label:node.name, label:node.address}};
}
}
The part that I didn't understand was "{children:{label:node.name, label:node.address}}". Office is simply a value object that contains two String properties: name and address.
The following return expression (modified from the question) ...
return {children:{label:node.name, body:node.address}}
... is functionally equivalent to this code ...
var obj:Object = new Object();
obj.children = new Object();
obj.children.label = node.name;
obj.children.body = node.address;
return obj;
The anonymous object returned in the question code complicates matters because it defines a property twice. In that case, the first declaration is used, and the subsequent one(s) are ignored. No compile-time or runtime error is thrown.
I think in Java you would call that a map or an associative array. In Javascript and Actionscript you can say this to create an object with certain properties:
var myobject = {
'prop1': 100,
'prop2': {
'a': 1
}
}
trace( myobject.prop1 ); // 100
trace( myobject.prop2.a ); // 1
In your example it's just returned as a nameless object.
return {children:{label:node.name, label:node.address}};
Means you are returning a new Object. The {} are the Object's constructor, and in this case its an Anonymous object.
Thank you both for the quick response. So if I understand your explanations correctly, the return statement is returning an anonymous object, and this object has only one property named "children", which is again an associative array - ok, here is the part I don't quite understand still, it seems that both properties in this array are named "label", is this allowed?