What is the best method to use ng-repeat in a single location?

I am looking to display the names from the array

[{'id' : 0, 'name' : 'first'}, {'id' : 1, 'name' : 'second'}]

<li ng-repeat="x in array"><strong>Names:</strong>{{x.name}}</li>

The current code displays 2 li's, but I want it to show: Names: first, second

Can anyone help me achieve this?

Answer №1

To avoid repeating the <li> tag, you should utilize the ng-repeat directive in a different element nested within the li tag:

<li>
  <strong>Names:</strong>
  <span ng-repeat="x in array">
    {{x.name}}
  </span>
</li>

Answer №2

To improve the structure, move the ng-repeat directive inside a span element within the li element.

<li><strong>Names:</strong><span  ng-repeat="x in array">{{x.name}} </span>

View the demonstration below:

angular.module("app",[])
.controller("ctrl",function($scope){
$scope.array = [{'id' : 0, 'name' : 'first'}, {'id' : 1, 'name' : 'second'}]

})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 <li><strong>Names:</strong><span  ng-repeat="x in array">{{x.name}} </span></li>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Effective technique for connecting client-side JavaScript with server-side node.js

I am striving to create a compact website featuring field auto-completion, drawing suggestions from the server's database (utilizing Node.js + MySQL). What approaches can I take to establish client-server communication as the user inputs data into a ...

When utilizing Ionic with Angular, it is difficult to access the hardware back button on mobile devices that have buttons located within the display/screen

When trying to access the hardware back button in my app, I encountered an issue where I couldn't produce an alert message to the user before the app closed. After posting a question on Stack Overflow (link of the question) and receiving help from the ...

Guide on how to append input field data to a table using jQuery

My current project involves working with a table, and I have encountered some challenges along the way. Typically, I have 4 input fields where I can input data that is then sent to the table in my view. However, if I exceed 4 values and need to add more, I ...

What is causing the Jquery repeater to not trigger .keyup and .change events on items beyond the second one?

I noticed that the .keyup and .change events are only triggered in the first input field and not after I add a new item. Is there a way to make these events trigger when adding a new field? http://jsfiddle.net/q8pcoaxf/ $('.field').on(& ...

AngularJS is throwing an error because it can't find a function called 'undefined' in Controller xxx

Just diving into the world of Angular. I'm following an example from a reputable book, but encountering an issue with the Cart Controller not being recognized as a function. Here's the code snippet causing trouble: HTML: <!DOCTYPE html> & ...

Error message: "Error creating tags using the Tag-It jQuery plugin"

I recently started using the tag-it jquery plugin available at https://github.com/aehlke/tag-it var ip_elem = $('#my-tags'); ip_elem.tagit({ removeConfirmation: false, caseSensitive: false, allowDuplicates: false, allowSpaces: t ...

Troubleshooting issues with applying styles in Vue framework when configured with webpack

I'm facing an issue with setting up the Vue framework using webpack. Specifically, I'm having trouble with styles not being applied when included in the <style> tag within single file components. Despite following several tutorials on this ...

Scrolling up or down in an HTML webpage using a script

Seeking a code snippet for my website that will allow me to achieve the following functionality: Upon clicking on text_head1, a list of lines should scroll down. Subsequently, when I click on text_head2, the previous list should scroll up while the new l ...

Is it possible to incorporate Nth child into JavaScript?

Is it feasible to implement an Nth Child in the following code snippet? $(function() { var count = $(".parent a").length; $(".parent div").width(function(){ return ($(".parent").width()/count)-5; }).css("margin-right","5px"); }); ...

"Oops! Looks like there is an issue with the configuration of the builder. Try running `npm run storybook

Encountering an error when attempting to execute npm run storybook following what seems like a smooth installation of Alpha 7. Any suggestions on where to begin troubleshooting this issue? https://i.sstatic.net/EEFx4.png ...

Using Flask and AngularJS: Managing Scope in a Controller with Flask Templating

Currently, my primary objective is to create a table with sortable columns. While following a tutorial and attempting to implement it into my project, I have encountered an issue. It seems that the structure of my code will not allow this functionality to ...

Can you indicate a specific version of an npm module without making changes to the package.json file?

I am looking to update the version of a npm module without making changes to the package.json file. I want to avoid forking the repository if possible. If the package.json appears similar to this: ... "dependencies": { "iwan ...

Is there a way for me to detect if the user has manipulated the CSS or JavaScript in order to alter the look of my website?

Is there a way to determine if someone is utilizing script or CSS extension tools? For instance, if they have adjusted alignments, applied display: none; to multiple elements, or utilized jQuery's .hasClass to manipulate divs. ...

What could be causing Ajax's html() function to create a loop that never ends?

Is there a way to incorporate an animation during the database operation and update the table content in the HTML document once the operation is completed? <script> var jobj = new Object(); jobj.uid = <?php echo "'".$_SESSION['user_ ...

Access the $event object from an Angular template selector

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script> <input type="file" #myFile multiple /> <button (click)="onDelete(myFile.event)">DeleteFiles</button> My code snippet is experienci ...

Reverse the order of jQuery toggle animations

Looking for something specific: How can I create a button that triggers a script and then, when the script is done, reverses the action (toggles)? (I am currently learning javascript/jquery, so I am a beginner in this field) Here's an example: ...

Guide to Implementing i18n-iso-countries Library in React

I am currently developing a React application and attempting to utilize the i18n-iso-countries package to retrieve a countries object in English where keys represent iso codes and values represent country names. This process is straightforward in Node.js, ...

The Angular strap's modal appears to be void of any content

I'm having trouble getting the angular-strap modal to display properly with an external template. What could be the issue? <!DOCTYPE html> <html ng-app="myApp"> <head> <link data-require="<a href="/cdn-cgi/l/email-prote ...

What is the best way to format two distinct headers using ui-router?

Currently, I am working on refactoring a project using AngularJS 1.4.2 and ui-router. However, I am uncertain about the best architecture to implement for this change. At the moment, we are utilizing $state.go("main"); to navigate to the main route and al ...

The S3 signature verification failed while generating a signed URL on the server-side using Node.js

Trying to upload a video file to my bucket using a pre-signed URL in angular4. Instructions: let s3 = new AWS.S3(); s3.config.update({ accessKeyId: process.env.VIDEO_ACCESS_KEY, secretAccessKey: process.env.VIDEO_SECRET_KEY }) ...