Save a collection of controller instances within a separate controller in AngularJS

I am in need of an angular example where one controller wraps another. For instance, I am looking to divide some logic between EndpointListController and EndpointController.

EndpointListController will handle retrieving data from storage, along with functions applicable to the entire list, whereas EndpointController will focus on individual endpoints.

It would be great to iterate through them using ng-repeat and directly call methods on each endpoint, like so:

<table ng-controller="EndpointListController">
    <tr ng-repeat="endpoint in endpoints">
        <td><input type="checkbox" ng-click="endpoint.select()"></td>
        <td>{{endpoint.label}}</td>
        <td><span class="label label-info">2014-10-10 23:59</span></td>
        <td><span class="label label-success">success</span></td>
        <td><a href="" class="glyphicon glyphicon-cloud"></a></td>
    </tr>
</table>

Currently, I am having to do something like this:

<tr ng-repeat="endpoint in endpoints" ng-controller="EndpointController" endpoint-data="{{endpoint}}">

This approach feels a bit cumbersome...

Is it actually feasible to achieve what I'm aiming for with angular? Perhaps I'm approaching this incorrectly, any guidance in the right direction would be highly appreciated.

Answer №1

This directive for container is quite impressive.

Check out this plunker

You can streamline your widget code to something like this:

<end-point-list class="table">
  <end-point ng-repeat="ep in endpoints" scope="ep" func="selectEp(scope)">
  </end-point>
</end-point-list>

Furthermore, you have 2 directives where one relies on the other similar to:

app.directive("endPointList", function(..
 return {
   controller:'EndpointCtrl',
//
app.directive("endPoint", function(..
   require:'?^endPointList',

This setup allows for an isolated scope on the children while still being able to communicate with the controller.

I didn't address how this connects to actual endpoints, unsure if that was part of the query?

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

Animating with React using the animationDelay style does not produce the desired effect

Is there a way to apply an animation to each letter in a word individually when hovering over the word? I want the animation to affect each letter with an increasing delay, rather than all at once. For example, if scaling each letter by 1.1 is the animatio ...

The execution of 'observe' on 'MutationObserver' failed because parameter 1 is not the correct type of 'Node'. Ensure to use select2() instead

Attempting to implement select2 for dynamically loaded data via ajax, I am encountering the error mentioned above. What could be the issue? Below is the code snippet in question: $(document).on('change', '[name="country"]', fu ...

How to eliminate the ng-component tag from an Angular 8 table row template

I currently have a dynamic table component with 2 modes: Normal table - functioning properly Custom Row Template - encountering issues due to Angular adding the <ng-component> tag The logic within the TableComponent is not the main concern, it&apo ...

Exchange one HTML element with a different HTML element

I've been attempting to change an HTML tag using PHP or jQuery. The current default tag is: <li class="dropdown"> <a href="index.html" class="dropdown-toggle"> Home</a></li> My desired replacement for the above HTML tag is: ...

Encountered an error while attempting to access the 'type' property of undefined within the Redux store for an action defined in an external package

In my quest to expand my knowledge of React (coming from an ASP.NET background), I encountered a challenge. I have multiple React applications where I intend to utilize common UI components, so I decided to extract these into a separate npm package. This a ...

Creating dynamic forms in Angular with partial dynamicity

I'm working on streamlining the process of creating forms using AngularJS. My end goal is to be able to simply write something like: <form> <field-div label="Name"> <field which="form.name"></field> </field-div> ...

View an image in advance of uploading it and concealing any broken images

The foundational code for previewing an image before it is uploaded can be found at this link. Here are the codes: <script type="text/javascript"> function readURL(input) { if (input.files && input.files[0]) { var ...

Sails.js seems to be malfunctioning, as it does not seem to be recognizing the term 'sails'

It seems like I'm encountering an issue with the 'sails' command not being recognized on my Windows 10 system. Despite following all the installation steps, including globally installing Sails.js through npm and ensuring Node is installed, I ...

Select state and city options similar to the national breakdown page

I'm attempting to replicate a state and city selection box similar to the one on the NTTS Breakdown website. You can see it in action here: When you select a state on the left side of the webpage, the city selection box displays "loading data" and th ...

The presence of multiple renderings occurring due to Google Maps InfoBox and an AJAX call

I'm encountering a problem with my implementation of the InfoBox and I'm looking for insights on potential solutions. Currently, I have around 1000 client-side markers that are dynamically added to the page. They are created using the following ...

Disabling the Autocomplete Drop-Down Arrow

Can the drop-down arrow icon be removed from the material-ui Autocomplete react component? My current view includes a blue arrow that I'd like to remove, opting instead for text to automatically drop down as I type. https://i.stack.imgur.com/ZTLYu.p ...

I am unable to showcase the image at this time

Hey there, I'm having an issue with displaying an image stored inside the NextJS API folder. The alt attribute is showing up fine, but the actual image isn't displaying. When I console.log the image data, everything seems to be in place. Can anyo ...

What is the best way to calculate the number of squares required to completely fill a browser window in real-time?

I am creating a unique design with colorful squares to cover the entire browser window (for example, 20px by 20px repeated both horizontally and vertically). Each square corresponds to one of 100 different colors, which links to a relevant blog post about ...

There seems to be a glitch in the AJAX code

I am currently working on a project that involves displaying categories and subcategories of products on a webpage. When users click on either a category or a subcategory, AJAX is used to send the selected item to a php script which then generates HTML cod ...

Having difficulty uploading an image to Facebook through the graph API

I have a requirement to upload a photo to Facebook using the Javascript SDK, but I am experiencing some difficulties: Firstly, FB.login(function (response) { if (response.authResponse) { va ...

What is the best way to pass a value from one directive to another in AngularJS?

Here is the code snippet from my index.html file: <body ng-controller="MainCtrl"> <search myname="myval" change-client='client()'></search> <pagination></pagination> </body> </html> and app.js conta ...

What is the timing for running tests using Yeoman AngularJS framework?

Recently, I created a compact Yeoman AngularJS project. Whenever I enter the command grunt serve, the application is launched and displayed in the browser. Surprisingly, whenever I make adjustments to a test, Grunt automatically reruns the test and provide ...

Verify whether the content within the Div has been modified

I am currently making changes to content within a <div> element. I would like to determine if the data in the <div> has been modified and, if so, save it in a session to persist on refresh. How can I verify if the data has been edited and then ...

ActivatedRoute not receiving the parameter value

Having trouble retrieving the parameter from the route and passing it to a function within the component which then communicates with the service. Initially tried placing the parameter retrieval in the NgInit but moved it to the constructor, still no succ ...

An error was encountered because it was unable to read properties of undefined, specifically in trying to access 'navigate'

Just diving into the world of react native and react navigation, I encountered this puzzling error. Uncaught TypeError: Cannot read properties of undefined (reading 'navigate') I'm scratching my head because I am using the exact same code ...