From the schema getting field name and response have value for that field name
{{ Response.{{ fieldname }} }} in angular
getting above error.
Try {{ Response[fieldName] }} instead. The syntax for accessing a dynamic property is in Typescript is obj[prop] where prop is a string containing the property's key.
Here is a related question: Dynamically access object property using variable
Related
I often get this error during development, and I can’t find where it happened and with which variable:
Cannot read property '0' of null
<div id="vueApp" > ... {{probablyNotArray[0]}} ... </div>
How can i get the "probablyNotArray" name?
You should see the code that causes the error on DevTool's sources tab, if you click (vue.js:11649)
Is your variable an array? Are you accessing the data inside of a loop or are you referencing it directly to the template? In that case you would need to use:
{{ this.probablyNotArray[0] }}
Judging by the name of the array, do you need to carry out a check that the variable exists or that its an array?
{{ Array.isArray(probablyNotArray) ? probablyNotArray[0] : probablyNotArray }}
So instead of returning the index of the variable if its not an array, we return the variable.
I'm using axios for API calls and everything works, but I have to specify blank values for mustache properties first.
{{page_data.title}}
will give an error, even though axios WILL be populating the value.
I can overcome this by first setting:
page_date.title: ''
BUT this becomes complicated, and counterproductive, with array data.
What would be the solution for this?
You could use the conditional ternary operator to check if the key is in the object first and only if it is, use it's value, e.g.:
{{'title' in page_data ? page_data.title : '' }}
Otherwise, you could use Lodash's _.get method, e.g.:
{{ _.get(page_data, 'title', '') }}
_.get is also useful for when you want to get a "deep" property, e.g.:
{{ _.get(page_data, 'article.title', '') }}
You can try using "v-if" before you render {{page_data.title}} E.g
<p v-if="page_data.title"> {{page_data.title}} </p>
I have a question about checking if some field in object exists.
I want to print all categories which user has so I'm doing something like this:
<ul *ngIf="user.categories.length > 0" *ngFor="#category of user.categories">
<li>
{{category.name}}
</li>
</ul>
The reason? All the data are PROPERLY printed, but I'm getting an error in web console like this:
Cannot read property 'name' of null
But when I do something like:
<ul *ngIf="user.categories.length > 0" *ngFor="#category of user.categories">
<li *ngIf="category">
{{category.name}}
</li>
</ul>
Then all is okay.
Am I doing something wrong or maybe I have to check this every time? Have you ever had a problem like this one?
basic usage
Use the safe-navigation operator
{{category?.name}}
then name is only read when category is not null.
array
This only works for the . (dereference) operator.
For an array you can use
{{records && records[0]}}
See also Angular 2 - Cannot read property '0' of undefined error with context ERROR CONTEXT: [object Object]
async pipe
With async pipe it can be used like
{{(chapters | async)?.length
ngModel
With ngModel currently it needs to be split into
[ngModel]="details?.firstname" (ngModelChange)="details.firstname = $event"
See also Data is not appending to template in angular2
*ngIf
An alternative is always to wrap the part of the view with *ngIf="data" to prevent the part being rendered at all before the data is available to prevent the dereference error.
There seems to be some magic happening here for {{ settings[a_prop] }} on a product page. It seems that {{ settings[a_prop] }} is equivalent to the property a_prop_productname in my settings.html (instead of a_prop, which makes more sense to me). This is all happening in my theme's product.liquid.
Can anyone explain where productname is getting pulled from? Also, normally liquid uses dot notation for settings... why do brackets work here? I can't find any examples anywhere on the internet.
https://docs.shopify.com/themes/liquid-documentation/basics/handle#handles-created
Shopify will automatically create handle based on the product/page/whatever title you provide.
https://docs.shopify.com/themes/liquid-documentation/basics/handle#attributes-handle
You can do both {{ obj[attr] }} or {{ obj.attr }} to access an object attribute.
{{ obj[attr] }} means "access the property on obj with the value of the variable attr" and {{ obj.attr }} means "access the property attr on obj".
HTML:
<input type="text" size="15" maxlength="79" value="" name="username">
As you can see, no ID. The HTML above is a textbox that i want to auto fill in whit my value as soon as i start the webpage whit my code.
this is what i found:
WebBrowser1.Document.Forms(0).GetElementsByTagName("username")(0).SetAttribute("value", (Text))
But whit this i get the error:
Value of '0' is not valid for 'index'. 'index' should be between 0 and -1.
Parameter name: index
What am i doing wrong?
This isn't going to find any elements:
WebBrowser1.Document.Forms(0).GetElementsByTagName("username")
"Tag name" doesn't mean the value of the name attribute, it means the name of the HTML tag itself. Like this:
WebBrowser1.Document.Forms(0).GetElementsByTagName("input")
Of course, this is likely to return multiple matched elements, so you'll need to further identify which one you want to modify. The point being that you should do some error checking to make sure that it finds anything, because trying to index an empty collection will result in an error:
WebBrowser1.Document.Forms(0).GetElementsByTagName("username")(0)
Since the collection has no elements, there is nothing at index 0.
May be u could try
Me.WebBrowser1.Document.GetElementByName("username").SetAttribute("Value", txtUsername.Text)