Inquire about understanding Mean.js through form submission

Hey there,

I'm looking to create a search engine for an application using JS MEAN.

I have a database with various elements and I want users to fill out a form to see the results in a separate view.

I haven't had much luck so far, I've done some reading but haven't found any concrete solutions.

How can I send the search parameters from the client controller to the server controller and display the results in a new view?

I want users to be able to search by type, color, and date range - all of which are already stored in the database.

Could someone provide me with a simple example of how to handle this transaction between the search form, client controller, and server controller?

Answer №1

If you're seeking an answer, allow me to provide some insight. The code is available for review here:

<section ng-controller="BooklistPaginationController" ng-init="init(10)">

....
<div class="row">
<div class="col-xs-12 col-md-12 col-sm-12 col-lg-12">
<div id="filter-panel" class="filter-panel" collapse="searchIsCollapsed">
<div class="panel panel-default">
<div class="panel-body">
<form class="form-inline" role="form">
    <div class="form-group">
    <label class="filter-col" for="pref-search">Texto:</label>
    <input type="text" class="form-control input-sm" id="pref-search" ng-model="text">
    </div><!-- form group [search] -->
    <div class="form-group">
    <label class="filter-col" for="pref-orderby">Orden:</label>
    <select id="pref-orderby" class="form-control" ng-model="order">
    <option ng-repeat="x in optionsOrder" value="{{x.value}}">{{x.text}}</option>
    </select> 
    </div> <!-- form group [order by] --> 
    <div class="form-group">
    <label class="filter-col" for="pref-perpage">Elementos página:</label>
    <select id="pref-perpage" class="form-control" ng-model="itemsPerPage">
    <option ng-repeat="x in optionsItemsPage" value="{{x.value}}">{{x.text}}</option>
    </select> 
    </div> <!-- form group [rows] -->
    <button ng-click="find()" class="btn btn-danger" style="margin-top: 4px;">
    <span class="glyphicon glyphicon-search"></span> Buscar
    </button>
</form>
</div>
</div>
</div>
</div>
</div>        

Provided above is the interface layout. This includes a form where you can search using text with sorting and pagination options. Additionally, it's essential to incorporate the controller to interact with the server for conducting searches.

angular.module('booklists').controller('BooklistPaginationController',     ['$scope', 'Booklists',
function ($scope, Booklists) {

$scope.searchIsCollapsed = true;

$scope.optionsItemsPage = [
    {text : "10", value : "10"},
    {text : "30", value : "30"},
    {text : "50", value : "50"}
];

$scope.optionsOrder = [
    {text : "Descendente", value : "asc"},
    {text : "Ascendente", value : "desc"}
];

$scope.optionsStatus = [
    {text : "Todos", value : ""},
    {text : "Borrador", value : "draft"},
    {text : "Publicado", value : "public"}
];

$scope.init = function(itemsPerPage){
    $scope.pagedItems = [];
    $scope.itemsPerPage = itemsPerPage;
    $scope.currentPage = 1;
    $scope.status = 'public';
    $scope.order = 'desc';
    $scope.find();
};

$scope.pageChanged = function () {
    $scope.find();
};

$scope.find = function () {

    var query = { page:$scope.currentPage,
                  itemsPerPage:$scope.itemsPerPage,
                  order:$scope.order,
                  status:$scope.status,
                  text:$scope.text
                };

    Booklists.query(query, function (data) {
        $scope.pagedItems = data[0].booklists;
        $scope.total = data[0].total;
    });
};
}
]);

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

Is it achievable to animate dynamic height using CSS? Open to JS alternatives as well

I am currently utilizing AngularJS, which enables me to utilize ng-show and ng-hide in order to display or hide elements based on a logical condition. My goal is to animate the size changes of the container when the child objects are shown or hidden, creat ...

Finding and retrieving the checked checkboxes in Selenium WebDriver without using the name or xpath

Can you help me figure out how to identify the selected checkbox from a list of checkboxes when no name or xpath is provided? Here is an image of the checkbox: enter image description here This is the HTML code generated: <div class="c ...

What could be causing my CSS transitions to fail when using jQuery to add classes?

I'm currently working on a website and I'm facing an issue with the transition not functioning as expected. The problem persists even when the 7.css stylesheet is removed and interestingly, the transition works fine when using window:hover. My a ...

Interactive hover effect in JavaScript displays a larger version of other thumbnails when hovering over a dynamically loaded thumbnail image, instead of its own full-size image

I recently began teaching myself PHP and Dreamweaver with the help of a video tutorial on building data-driven websites using Dreamweaver. My goal is to create a dynamic table with 6 columns and 20 rows. column1 | column2 | column3 | colu ...

Can I incorporate NodeJS modules such as "oauth" into my Firefox extension?

I am diving into the world of Firefox addons for the first time. My project entails making calls to Twitter's APIs, which means I require an oauth library to kick things off. After some research, I came across an existing library in the npm package r ...

How can I make my navbar stay fixed in place and also activate the transform scale functionality?

After fixing the position of my navbar with the class "top," I noticed that the transform property scale does not work on the div element I applied. The hover effect on the box only works when I remove the position from the navbar. This is the HTML code: ...

Guide to implementing code on a designated path with access to various services

I'm contemplating the best approach to configuring a route specifically designed to utilize a service call and then redirect. Currently, I've resorted to this workaround: $routeProvider.when('/talks', { template: '<div> ...

issue retrieving data from live website created with next.js

Hello, I've exhausted all possible avenues to identify the cause of the error occurring on my live website built with NEXTJS. I have observed that this error only occurs when I reload the website. It's worth noting that I can successfully login ...

What is the process for changing one tag into a different tag?

Can someone help me with this issue? I need to change the tags in a given string from <h2> to <h3>. For example, turning <h2>Test</h2><p>test</p> into <h3>Test</h3><p>test</p>. Any suggestions o ...

A new module is unable to load Angular Material

Recently, I developed an Angular material module similar to a core module. import { NgModule} from '@angular import {MatCheckboxModule} from '@angular/material/checkbox'; @NgModule({ imports: [ MatCheckboxModule ], exports: [ ...

Executing jQuery on page update can be achieved by utilizing event handlers to trigger

I have implemented jQuery multi-select to enhance the user experience of my Django app's multiselect feature. Upon initially rendering my page, I included the following script to bind any elements with the class 'multiselect' to the jQuery m ...

Determine whether a click event originated from within a child window

Currently, I am utilizing window.open to initiate a new window in javascript and my goal is to identify clicks made within the child window. Essentially, if a click event occurs in the child window, I aim to modify the parent window accordingly. I have a ...

Retrieve information from both the client and server sides within NextJS

Looking to integrate a third-party API for data fetching in certain components within my NextJS project. The goal is to have the server pre-render these components with the API for optimal SEO benefits, but also enable client-side fetching of component pro ...

Click event in safari failing to trigger on iPhone

Issue with click event on mobile Safari browser when using an iPhone In a React class component, the click event listener is triggered on the window when opening the menu. This functionality works correctly everywhere except for iPhone Safari. toggleMenu ...

The process of transmitting messages back and forth between a popup script and a content script

I am in the process of developing a Chrome extension that involves sending data requests from a popup script to a content script (via a background script), analyzing the request on the content script, and then sending back a response (again through the bac ...

Innovative solution for detecting and replacing undefined object properties in Angular 2 with TypeScript

After encountering the issue of core.umd.js:3523 ORIGINAL EXCEPTION: Cannot read property 'fullName' of undefined I realized that the Exception stemmed from a Template trying to access a specific property: {{project.collaborators["0"]["fullN ...

Seeking a method to attach information from a div to a hyperlink

As a complete novice in the world of CSS websites, I find myself struggling to accomplish what seems like a simple task. I am working with an automatically generated CSS/JavaScript website where on the "individual" page, a person's name is listed with ...

13 Helpful Tips for Resolving Hydration Failure Due to Discrepancy in Custom Dropdown Display between Server and UI

Recently, I embarked on a project utilizing the latest version 13 of Next.js with its new app directory feature. As I integrated a custom dropdown into one of my pages, an error surfaced: "Hydration failed because the initial UI does not match what was ren ...

Whenever I attempt to send a message in React, it keeps displaying the same message repeatedly

https://i.stack.imgur.com/UBkMK.png The image above illustrates the issue at hand. You can also check the console in the bottom right corner for more details. I am currently working on a one-to-one chat website using Socket.io with React, Node.js, and Exp ...

Ways to alter the color of an icon when hovering over it

Is there a way to change the color of a material icon inside an IconButton material component when hovering over the IconButton? I've tried adding a class directly to the icon, but it only works when hovering over the icon itself and not the IconButto ...