last day (15 days later) » 

6:29 PM
1
Q: Cannot create property on string angularjs

AntonI'm getting form from api request, some of this fields based on ng-options. The data for options comes from angular services. So on the page it looks like: after form has been opened: depends on key, fields can be: disabled for modifications enabled for modifications enabled for modificati...

 
I'm trying to follow what you are doing. Why do you have both rowKeys and rowData? What doesn't rowData do for you that rowKeys does being that rowKeys appears to be just the keys from rowData?
 
@jbrown so rowKeys has been created with only one purpose to get keys of rowData, the value for this keys comes from rowData
 
I forked your plunker plnkr.co/edit/xQpiZYwocRTSv1G1Ctzr?p=preview I know its not the complete solution but I stripped out some things (ng-diabled, ng-if, ...) to try and get down to what I think you're trying to accomplish. Let me know if I'm on the right track.
 
@jbrown you are definitely on the right way but Just noticed, I need to display keys..
 
I updated the plunker to show the key
 
6:29 PM
@jbrown sorry but it can't be done like this <div>Id: {{row.id}}</div>. The thing is the data always comes different, in this example I have 'id', in next time I don't have it, but instead of this have 'itemId,' that's why I used ng-repeat that to build form.
 
So, you're saying that not every object in the array is the same?
 
not always
so we have 8 object which is the same
but others can be different all time
it can be different amount
min 8 objects max 15
> so we have 8 object which is the same
ooops sorry about that
we have 8 objects which are the same all time
 
Within one array, you will have a mixture of objects?
 
so basically my array exactly looks like
[{
"id": 1839,
"eventTypeId": 1,
"occuredDate": "2016-05-28T00:00:00",
"title": "Check",
"description": "WEIGHT should be in the range of weight >= 45.5 and weight <= 180",
"outcome": "",
"studyId": 49,
"statusId": 1,
"severityId": 2,
"priorityId": 2,
"study": {
"id": 49,
"name": "Study 49"
},
"status": {
"id": 1,
"name": "New"
},
"severity": {
"id": 2,
"name": "Medium"
},
"priority": {
"id": 2,
"name": "Medium"
},
"reportedCompanyId": 2,
"reportedSystemId": 3,
the other array can be look like
[{
"itemId": 1839,
"eventTypeId": 1,
"occuredDate": "2016-05-28T00:00:00",
"title": "Check",
"description": "WEIGHT should be in the range of weight >= 45.5 and weight <= 180",
"statusId": 1,
"severityId": 2,
"priorityId": 2,
"study": {
"id": 49,
"name": "Study 49"
},
"status": {
"id": 1,
"name": "New"
},
"severity": {
"id": 2,
"name": "Medium"
},
"priority": {
"id": 2,
"name": "Medium"
},
"createdDate": "2016-05-28T10:28:30",
"externalEventId": 1909,
"eventType": {
 
Ok, so the arrays might be different but the object structure within a single array will be the same?
 
6:41 PM
yeah right
 
How many different types (structure) of objects are you dealing with?
 
numeric boolean string
null never comes
 
Sorry, let me word that differently...
is the name of key property the only property that can be different from one array to another? If so, how many different names do you have? So far, I've seen id and itemId
 
I don't know. depends of DB, the data comes from 10 different DB, each db has own standard for data structure
 
Ok, that's ugly. My advice would be to deal with the structure differences in javascript. Map everything into one object structure before passing to HTML. Trying to account for possibly 10 different objects in HTML is hard to follow, a poor performer, and downright ugly to look at. Just my 2 cents
 
6:54 PM
I thought about it, but ng-repeat looked like easy way for me
to show keys and valie for this keys
so what is the problem
I think you have some thoughts
I mean the problem with property
 
ng-repeat is great if your using it on a collection of objects that all have the same properties. If they don't then you're going to have to something very hacky to conditionally render the elements associated with disparate properties
 
hmm.. but do you know what?
may I should tell it before
I have modal form
that to create new event
<form ng-submit="onSubmit(vmodel)" novalidate role="form" class="form-vertical">

<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" id="title" placeholder="Title" ng-model="vmodel.title">
</div>

<div class="form-group">
<label for="studyId">Study</label>

<select class="form-control" ng-model="vmodel.studyId" id="studyId"
ng-options="item.id as item.name for item in eventLov.studyOptions()">
</select>
</div>
<div class="form-group">
<label for="eventTypeId">Event Type</label>
<select class="form-control" ng-model="vmodel.studyId" id="studyId"
ng-options="item.id as item.name for item in eventLov.studyOptions()"> it's using same way and it works
 
I don't see where you're handling the key in that code
 
7:11 PM
thru this form you set only main 8 objects, but key is strict like in your example
hold on
what if just use ng-repeat="(key, value) in rowData"
define in controller if key is object
does it help?
 
You'd still just be getting the array key. That won't yield id, or itemId, or whatever the other properties are called
 
deadlock condition
check this up
couple filters and done
 
7:30 PM
If that simplistic UI satisfies your requirements, the go for it. But I thought you had disparate model structures and foreign key that you're handling with select elements.
 
No, my point was I have different structure with different keys, but main 8 objects are the same
and I need to be able to modify 3 of them
but if I modify object severity so I have to return to db modified severityId, not severity.name or severity.id
that's y point
 
Ah
 
this part
"statusId": 1,
"severityId": 2,
"priorityId": 2,
"study": {
"id": 49,
"name": "Study 49"
},
"status": {
"id": 1,
"name": "New"
},
"severity": {
"id": 2,
"name": "Medium"
},
"priority": {
"id": 2,
"name": "Medium"
},
always the same
if I changed this "status": {
"id": 1,
"name": "New"
}, on this "status": {
"id": 2,
"name": "Closed"
}, so I have to return value "statusId": 2,
that how I see and how explain ti the guy who developed api
I mean middletier api
 
BTW - in your plunker you are using rowData[key]. Its not necessary, just use value
 
7:44 PM
Why are you doing this .... ng-if="!isObject(rowData[key])" In what case would it not be an object?
 
if this is not an object show this input if opposite show another one
thru this function isObject I'm getting object value
without it I see [object objet ]
 
ah
 
now it almost finished
Cannot create property 'statusId' on string 'status'
still same
 
yeah, cuz we're essentially right back where we started. hacky
 
it's headache
6 hours for one task
at least it looks better
I mean code
I have found this
if (hasApply) {
return function() {
var args = [];
forEach(arguments, function(arg) {
args.push(formatError(arg));
});
return logFn.apply(console, args);
};
}
args = ["TypeError: Cannot create property 'severityId' on …42/edetek%20ems/libs/angular/angular.js:26434:12)"]
13233
forEach(arguments, function(arg) {
arguments = [TypeError: Cannot create property 'severityId' on string 'severity' at fn.assign (eval at compil…]
13234
args.push(formatError(arg));
args = ["TypeError: Cannot create property 'severityId' on …42/edetek%20ems/libs/angular/angular.js:26434:12)"]
13235
});
13236
return logFn.apply(console, args);
13237
};
13238
}
13239

13240
// we are IE which either doesn't have window.console => this is noop and we do nothing,
13241
// or we are IE where console.log doesn't have apply so we log at least first 2 args
13242
return function(arg1, arg2) {
13243
logFn(arg1, arg2 == null ? '' : arg2);
13244
};
13245
}
13246
}];
13247
}
13248

13249
 
8:08 PM
the severity object doesn't have a property named severityId
So your code is puking on <select ng-if="isObject(rowData[key]) && key == 'severity'" ng-model="key.severityId"
should be <select ng-if="isObject(rowData[key]) && key == 'severity'" ng-model="key.id"
 
Cannot create property 'id' on string 'status'
 
did you change ng-model="key.statusId" to ng-model="key.id"?
 
yes
<select ng-if="isObject(rowData[key]) && key == 'severity'"
ng-model="key.id"
class="form-control rowValue"
id="severityId"
ng-options='item.id as item.name for item in severityOptionsFunc' >
<option value=''>{{value.name}}</option>
</select>
 
ok, so that's the code for severity. what about status?
 
<select ng-if="isObject(rowData[key]) && key == 'status'"
ng-model="key.id"
class="form-control rowValue"
id="statusId"
ng-options='item.id as item.name for item in eventService.statusOptions()' >
<option value=''>{{value.name}}</option>
</select>
 
8:20 PM
save your plunker so I can see where you are
 
I'm not seeing any errors in the console
 
what?
 
not in chrome anyhow
 
so it is working but not in chrome?
 
8:27 PM
no, its working in chrome ... and IE
 
how is it possible
could you fork and send me you plunk
 
I didn't make any changes. I just ran your plunk
 
wow
it is some kind of magic
it is working
so you can post it
I will submit it as answer
my 2 cents to your score
if you want
 
No that's ok. Glad you got it working
 
thank you so much
 
8:34 PM
I don't deserve credit. You got it working to your satisfaction even against me advice :)
 
I appreciate your help
 
no problem
 
at least you deserve it, cause spent coupe hours to help em
 
happy to help ... have a nice day
 
thanks you too
 

last day (15 days later) »