triggering the onsen's setMainPage function when clicked using a variable from ng-repeat loop

I need help customizing my Onsen UI splitView app to dynamically set the main page based on a variable received from a clicked item in a list generated by ng-repeat.

After researching ng-repeat and ng-click, I am still unable to achieve the desired outcome. Perhaps I am not understanding them correctly.

Below is the relevant code:

HTML

<ons-split-view 
 var="splitView"
 secondary-page="secondary.html" 
 main-page="main1.html" 
 main-page-width="60%" >
</ons-split-view>

<ons-template id="main1.html" >
    <ons-page ng-controller="ApkController as page">
            <ons-toolbar>
                <div class="center">List of pages</div>
            </ons-toolbar>
            <ons-list>
                <ons-list-item modifier="chevron" ng-repeat="content in page.contents" onclick="splitView.setMainPage(content.name'.html');">{{content.number}}. {{content.name}}</ons-list-item>
            </ons-list>
    </ons-page>
 </ons-template>

<ons-template id="secondary.html">
    <ons-page style="border-right: 1px solid #ddd;text-align:center; vertical-align:middle;">
        <ons-toolbar>
            <div class="left"><span class="toolbar-button--quiet navigation-bar__line-height" ><i class="fa fa-angle-left fa-lg" style="color: #666"></i> Back</span></div>
        </ons-toolbar>
        <table style="width:100%;height:100%;">
            <tr >
                <td style="vertical-align:middle;text-align:center">Please choose the page you want </td>
            </tr>
        </table>
    </ons-page>
 </ons-template>

<ons-template id="page1.html">
  <ons-page>
    <ons-toolbar>
      <div class="center"> Page 1 </div>
    </ons-toolbar>
    <ons-button onclick="splitView.setMainPage('main1.html')">Click</ons-button>
  </ons-page>
</ons-template>

<ons-template id="page2.html">
  <ons-page>
    <ons-toolbar>
      <div class="center"> Page 2 </div>
    </ons-toolbar>
    <ons-button onclick="splitView.setMainPage('main1.html');">Click</ons-button>
  </ons-page>
</ons-template>

<ons-template id="page3.html">
  <ons-page>
    <ons-toolbar>
      <div class="center"> Page 3 </div>
    </ons-toolbar>
    <ons-button onclick="splitView.setMainPage('main1.html')">Click</ons-button>
  </ons-page>
</ons-template>

Javascript

ons.bootstrap().controller('ApkController', function () {
    this.contents = something;
});

var something = [
{
    number : '78',
    name : 'page1',            
},
{
    number : '79',
    name : 'page2',
},
{
    number : '80',
    name : 'page3',
}];

You can also view the code on CodePen: http://codepen.io/fadynoor/pen/GJJMLx

The issue lies in inserting content.name into the setMainPage() function so it functions as intended.

I am new to Onsen UI and Angular, any suggestions would be greatly appreciated.

P.S.: This is my first time posting in this forum, apologies for any mistakes made.

Answer №1

If you implement the following adjustments, your code will be functional

<ons-list-item modifier="chevron" ng-repeat="content in page.contents" ng-click="showContent( content)">{{content.number}}. {{content.name}}</ons-list-item>

The JavaScript controller should resemble this

ons.bootstrap().controller('ApkController', function ($scope) {
  this.contents = something;

  $scope.showContent = function(content){
    splitView.setMainPage(content.name + ".html");

  };
});

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

Difficulty in defining the impact of a function on a single menu

Q:: How can I restrict a jquery function to apply only on a specific set of list items in my website? $("li").mouseover(function(){ $(this).stop().animate({height:'230px'},{queue:false, duration:10, easing: 'easeOutBounce'}) ...

The anchor tag causes the tooltip to display outside of the td element

One of my requirements is to display the click percentage for each link in an HTML template that is dynamically fetched from a database. I attempted to show the click percentage for each anchor link by adding them to the `data-title` attribute using jQuery ...

Node - Creating personalized error handling functions

Currently in the process of developing custom helper methods to eliminate redundancies, utilizing express-promise-router app.js has set up the error handler middleware //errorHandler app.use((err, req, res, next) => { //const error = a ...

ES6: utilizing properties and methods of a subclass that inherit from the superclass

While ES6 does not have abstract methods or properties, is it possible to access some methods or properties from the parent class in an inherited class? class ParentClass { constructor(){ ParentClass.checkChildPropertyAccessibility(); Pa ...

Can we integrate the Node.js API into Meteor?

Being new to Meteor.js, I've been wondering if it's possible to utilize the node API in my project. I've hit a roadblock and haven't been able to find any information on this topic despite spending a significant amount of time researchi ...

When redirecting to the same component, Vue.js hooks are not triggered

In my Vuejs project, I have two pages located at the same level with a common component. However, when I redirect from post/new to post/edit/:id, the beforeMount method is not being called. redirect() { this.$router.push({path: `home/post/edit/${this ...

Issues with npm @material-ui/core Button and TextField functionality causing errors and failures

I'm currently working on a React project and decided to incorporate the material-ui framework. After creating a component that includes a textfield and a button, I've encountered an issue where I can't interact with either of them as they s ...

Navigational menu that slides or follows as you scroll

Wondering if anyone knows of a straightforward jQuery or Javascript method to create a navigation sidebar that smoothly moves with the user as they scroll down a page. A good example can be found here: Any suggestions would be greatly welcome. ...

The issue persists with the JavaScript window.location script constantly refreshing

I am currently working on a small web application where I want to update 2 parameters in the URL using Javascript. However, every time I use "window.location.search = 'scene.html?name=' + person + '&scene=' + readCookie("scene");", ...

Difficulty arises when trying to extract specific information from an ajax response using the jQuery.filter

The code snippet below seems to be causing some trouble. It's supposed to filter HTML content that includes a div with the class "filtered_entries_box", but it's not working as expected. $.ajax({ "url" : "start.php", "type" : "POST", ...

The function react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_4__.jsxDEV(...) is not recognized

For my react-redux project, I utilized json-server as the server for managing orders. The status of each order is saved in the state within UiReducer and is then accessed in the "OrderStatusPage". The current NODE_ENV configuration is set to "development". ...

Caution: An invalid next.config.js file has been detected while running the Next.js project

Whenever I try to run my project, I encounter the following three warnings: 1- warn - We found some invalid options in your next.config.js file. The property webpack5 is not recognized and may cause issues (allowed properties are: amp, analyticsId, assetP ...

TypeScript enabled npm package

I am currently developing a npm module using TypeScript. Within my library, I have the following directory structure: . ├── README.md ├── dist │ ├── index.d.ts │ └── index.js ├── lib │ └── index.ts ├── ...

Tips for incorporating multi-lingual email templates into your node.js application

I integrated node email templates into my project to automatically send emails to users based on certain events. Check out the Node Email Templates GitHub page for more information. For sending emails with Node.js, Nodemailer is a great tool. While I wa ...

Unable to create canvas drawings using fingertips on mobile web browsers

Check out the code snippet below: canvas = document.getElementById("canvas"); ctx = canvas.getContext('2d'); tmp_ctx = element[0].getContext('2d'); element.bind('mousemove touchmove', function(event){ if(draw ...

Customize the asset path location in Webpack

I am currently working on a Vue application that utilizes Webpack for code minimization. Is there a method to dissect the chunks and adjust the base path from which webpack retrieves the assets? For example, by default webpack fetches assets from "/js" o ...

Learn how to retrieve the HTTP headers of a request using AngularJS

When working with AngularJS, I know that accessing an HTTP request's GET parameters is easy using: $location.search().parameterOfInterest But how can I access the HTTP headers of the request? It's worth noting that I'm not utilizing $http ...

Ways to resolve the issue "Module Not Found Error: Cannot locate module './src/bot/index'"

Whenever I run the command node src/index.js I encounter the following error message: Error: Cannot find module './src/bot/index' Require stack: C:\Users\MIMAR\Desktop\EJS\src\index.js What could be causing this er ...

The deprecated body parser is throwing an error due to the lack of the extended option

I am encountering an issue with my code and I'm not sure how to resolve it. Since I am new to the codebase, I feel completely lost and clueless about what steps to take. body-parser deprecated undefined extended: provide extended option index.js:20:2 ...

How can I convert an Array into a Dictionary using JavaScript?

Is there a clever method (perhaps using a map function) to restructure my data object from this: [ {id: 1, from: "1/1/2021", to: "1/2/2022"}, {id: 2, from: "1/3/2021", to: "1/4/2022"}, {id: 1, from: "1/5/2 ...