Remove brackets and quotations from JSON value - javascript

Hi I am using AngularJS on a WordPress site and when displaying custom field values using Angular tags in my partials HTML file such as {{post.manualest}}, it displays as ["1,500,000"]
How can I remove [" "] so that it shows only 1,500,000?

Since {{post.manualest}} contains an array you need ng-repeat
<p ng-repeat="tag in post.manualest">{{tag}}</p>
The ngRepeat directive instantiates a template once per item from
a collection. Each template instance gets its own scope, where the
given loop variable is set to the current collection item, and $index
is set to the item index or key.
https://docs.angularjs.org/api/ng/directive/ngRepeat

The data you received (in manualest key) is an Array. So either you can use the ng-repeat as #Vicky suggested or you can simply write in your HTML:
{{post.manualest[0]}}
Edit: Like #FuzzyTree already mentioned in the comment.

Related

Passing index value in append function in angular js

I am trying to create a chat box in angular, I made it some how but I feel the code is wrong when I click the members it show different member. Please someone correct the code here the link to Plunkerlink
$index will give you the index of the ordered item in UI(After Applying ngRepeat and orderBy) not in the index of the item in the data array. To elaborate this behavior, When I select the artist name "Hassum Harrod" the $index will return me the value as 2 but the same data is available at the index 3 from your data.json. You can pass the item itself to your AppendText(item) . I have modified your plnkr.
I hope it helps

tolowercase string Angular

Very simple issue I cant seem to resolve, my markup
<select class="testing" ng-model="Car_name" ng-options="item in categories['Car_name']">
I'm trying to change 'Car_name' to be 'car_name' however the server populated the ng-model & categories[] entries, so I'm not sure how I can watch and convert to lowercase in my controller.
If I could do
{{Car_name|lowercase}}
would be the easiest, but not sure on the format.
Option 1
You can do it by using angular.$filter option
Sample look like
<td ng-model={{ lowercase_expression | lowercase}}><td>
$filter('lowercase')()
More details Please see this angular document
Option 2
Please see this below discussion
AngularJS - ngOptions expressions
Option 3
You need to manually add a loop for your array. And convert to the object values to lower case by using toLowerCase() function , and finally push the object to new array.
This is built into AngularJS and can be access via angular.lowercase(string); and then used in your Controller like:
$scope.makeLowerCase = function(string){
return angular.lowercase(string);
};
Now use in your DOM like:
{{Car_name|makeLowerCase}}

Remove and Update json object using AngularJS

I have a json array with objects. Each object has bunch of key and values. Using ng-repeat to shown the object's in my html page. If i click edit for the particular object, an object will toggle on bootstrap modal. If changes made in the modal window, its directly affects the json object and instant changes should occur in UI. so i using a angular.copy to take an duplicate object and shown in the modal window. I want to do, if i click update button means within the modal dialog, splice the json object and insert the duplicated json object into the array within the same index. How can i do it. Here sample code
$scope.array = [{"ItemId":"20113",
"ItemModel":"C2",
"ItemName":"Nokia", .....},
{....},
{....},
{....}, ......]
I want splice index 2 in the array and insert an new object in the array as the same index of 2
Why are you using angular.copy?
If you were passing the object you want to edit, you wouldn't need to refres it afterwards. (sorry I misread that you needed an update button)
Although, to answer your question, your solution would be to replace the object by the new one :
$scope.array[index] = modifiedObject;

How To Get javascript Array in Code behind

This is javascript array
var data =['athar','naveed','123','abx'];
Now I want to access this array in code behind array or list variable. Don't want to use Hidden field.
If you want to use in anyother javascript function,you can simply use data[0] to access first element i.e.,athar.
data.length will give you the count of values present in the array.

How to use json array length in angular?

my pages uses lots of ng-repeat to generate table rows. If there is no data in an json array, there would be an empty table. I'm trying to skip generating table rather than an generate an empty one.
To do that, I need to check if the array length is 0. In js I can get array length using its length property:
$scope.data.errors.length === 0
But I can't use it in angular watcher, the following has no output
{{data.errors.length}}
And data.errors.length === 0gives false.
So is there a way to get json array length in angular?
You can use ng-show Ex.
<div ng-show=data.errors> your html </div>
Or you can use ng-repeat following code will execute if there is an error
<div ng-repeat="error in data.errors"></div>

Categories