in Education by
I need to use recursion in angular directives. Follow the code with the template without recursion. It is a left menu that must be created recursively. I'm not sure how to put the recursion. I tried ' </ leftmenu>', but so only the profile image appears several times. .directive('leftmenu', ['$compile', function ($compile) { return { retrict: 'E', scope: { menuLeft: '=?' }, template: '
' + '
' + '{{ menuLeft.profileName  }}' + '
' + '
' + '

{{ menuLeft.profileName }}

' + '
' + '
' + ' ', compile: function (element) { }, controller: function ($location, $http, $scope) { $scope.menuLeft = { "profileName": "", "profileImgSrc": response.data.msgSaida[0].profileImgSrc, "header": "", "itens": response.data.msgSaida[0].itens, "token": token }; } } } } }; JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
A little late to the party, if you're still looking to resolve this with a recursive directive, it depends what your data structure looks like, but assuming from what you've posted it looks like this: { "profileName": "", ... "items": [{ "label": "title1", "class": "class1", "items: [...] },{ "label": "title1", "class": "class1", "items: [...] }] } You can split them into two directives: One is the parent sidePanel directive that contains the top level One is the menuList directive that will recursively display sub items // profile image // profile name // etc where menu list template was like:
  • {{item.label}}
So in each instance of a menu object (label,class,items) the items will be converted into a sub menu-list. You might need to play with it a little and add in some other features.

Related questions

0 votes
    What are directives in Angular?...
asked Jun 30, 2021 in Technology by JackTerrance
0 votes
    What is the difference between AngularJS and Angular?...
asked Feb 25 in Technology by JackTerrance
0 votes
    Which of the following directives connects the value of the controls to the data? 1. ng-model 2. ng-app 3. ng-init 4. None of the above...
asked Jun 29, 2021 in Technology by JackTerrance
0 votes
    Which among the below directives belonging to the Cache-Control header of HTTP response provide information to the server that the ... -revalidate 3. no-cache 4. None of the above...
asked Jun 24, 2021 in Technology by JackTerrance
0 votes
    What is page directives in ASP.NET?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    Is it possible to add the numbers 1 to n recursively in Java with one return statement? How would ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    Is it possible to add the numbers 1 to n recursively in Java with one return statement? How would ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    Is it possible to add the numbers 1 to n recursively in Java with one return statement? How would ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I want to understand the following code: struct element{ element *a1; element *a2; int value; }; ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Given the following F# snippet: type A(children: A list) = member val P1 = "" member val P2 = " ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 6, 2022 in Education by JackTerrance
0 votes
    This is a moronic question. Here goes: I have two lists, candidates_input and constraint_input. The function ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    state one advantage and one disavantage of using recursion over iteration Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
    What is Recursion in Java? (a) Recursion is a class (b) Recursion is a process of defining a ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    Which of these data types is used by operating system to manage the Recursion in Java? (a) Array ( ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    What is recursion?...
asked Jan 18, 2021 in Technology by JackTerrance
...