AngularJS: engaging search experience

I'm just starting to learn AngularJS, and I have a project where I need to create an interactive search feature.

So far, this is what I have:

article/views/articles.html

<form class="form-inline">
   <div class="form-group">
        <label for="filter-text">Text </label>
        <input type="search" class="form-control" id="filter-text" placeholder="Search for text" ng-change="applyFilter();" ng-model="filters.text">
   </div>
   <div class="form-group">
        <label for="filter-date-start">Start Date </label>
        <input type="date" class="form-control" id="filter-date-start" placeholder="Start Date" ng-change="applyFilter();" ng-model="filters.date_start">
   </div>
   <div class="form-group">
        <label for="filter-date-end">End Date </label>
        <input type="date" class="form-control" id="filter-date-end" placeholder="End Date" ng-change="applyFilter();" ng-model="filters.date_end">
   </div>
</form>

<div class="hidden-sm hidden-xs col-md-6">
    <div 
            ng-repeat="article in articles"
            class="article"
            ng-include="'article/views/article.html'" >
    </div>
</div>

article/views/article.html

<div ng-hide="article.isHidden">
    <!-- Article HTML Content Here -->
</div>

article/article.js

angular
.factory('articleRetriever', function ($http, $q){

    this.getLast = function( id ){

        var url = 'http://localhost:8080/articles/';
        if (id) url += id;

        return $http.get(url ,{'Access-Control-Allow-Origin': 'localhost:*'})
            .then(function(response) {
                var articles = [];
                for (var idx in response.data.data) {
                    var article = response.data.data[idx];
                    article.isHidden = false;
                    articles.push(article);
                }
                return articles;
            });
    };
return this;
})

.controller('ArticlesCtrl', ['$scope', 'articleRetriever', function($scope, articleRetriever) {
    $scope.articles = [];
    $scope.filters = { tag: null, date_start : null, date_end : null, text : null };
        articleRetriever.getLast()
            .then(function(arrItems){
                $scope.articlesLoaded = arrItems;
                $scope.articles = $scope.articles.concat(arrItems);
            });

    $scope.applyFilter = function () {

        var contains = $scope.filters.text.split(' ');

        for (var idx in $scope.articles) {;
            $scope.articles[idx].isHidden = true;
            if (contains.length > 0) {
                for( var jdx in contains) {
                    if ($scope.articles[idx].body.toUpperCase().indexOf( contains[jdx] ) > -1)
                        $scope.articles[idx].isHidden = false;
                    if ($scope.articles[idx].title.toUpperCase().indexOf( contains[jdx] ) > -1)
                        $scope.articles[idx].isHidden = false;
                }
            }
        }
    };

});

However, even after entering text into the input field, the changes made to $scope.articles do not hide the article's div in article/views/article.html. Could someone please help me understand why and provide a solution?

Thank you :-)

Answer №1

Apologies, I realized that the search form was not located within the designated div containing the ng-controller="ArticleCtrl" directive. Once I moved it inside, everything functioned flawlessly.

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

Attempting to create a pathway for removing a profile and user from mongoDB

Hello, StackOverflow community! This is my initial post here and I'm excited to seek guidance. I recently created a delete route in Express to delete both a user and their profile: // @route DELETE api/profile/ // @desc Delete user and profile / ...

Box Pattern with Pop-Up Modal

Check out the grid of squares I've coded below: <div class='square-container'> <div class='square'></div> <div class='square'></div> <div class='square'></div& ...

Is it feasible to bypass the dialog box on beforeunload?

Currently, I am utilizing jQuery's bind method like so: $(window).bind('beforeunload', function() { //my code return ""; } In Mozilla Firefox and IE8, everything works smoothly without including the "return "";" statement. No pesk ...

Enhance the functionality of selectize.js by incorporating select options through ajax

I'm currently working on implementing options to a select box using AJAX and selectize.js. When not using selectize.js, everything functions correctly. The two select boxes are interconnected so that when one is updated, the values in the other select ...

How can you make the browser window scroll horizontally when a div is clicked using jQuery?

I have an image of an arrow inside a div. The div is positioned fixed in the bottom right corner of an extremely wide page. Is there a way to utilize jQuery to scroll the window 600px to the right each time the arrow is clicked? Also, can I detect when th ...

Using Python Selenium to create a login page with Javascript

Attempting to access a page using Python selenium package for certain activities is proving challenging. Despite the following code being written, an error message of "the Class is not found" keeps appearing. To proceed with using send_keys(), it's ne ...

Adding a specific element to an array using JQuery

I am in the process of developing a web application using jQuery to track goals and habits. Users can set a main goal such as 'Discipline' and then add sub-goals or habits related to that main goal (e.g. 'exercise every day'). Organizi ...

Angular component equipped with knowledge of event emitter output

I have a custom button component: @Component({ selector: "custom-submit-button" template: ` <button (click)="submitClick.emit()" [disabled]="isDisabled"> <ng-content></ng-content> </butto ...

When I utilize the redux connect function, the class information in my IDE (PhpStorm/WebStorm) seems to disappear

When I use the connect function from redux, it seems to hinder my IDE (PhpStorm) from "Find Usages" on my classes. This is likely because connect returns any, causing the type information from the imported SomeClass file to be lost. export default connect ...

Next.js pages do not respond to event listeners

Something strange is happening in my Next.js project. I've implemented a header that changes color as the page scrolls using the useEffect hook: The hook in the Header component looks like this: React.useEffect(() => { window.addEventListener(&a ...

Alter the color of textbox text using JavaScript

I have a text input field. When clicked, I want to change the text color style using JavaScript. Previously, I successfully achieved clearing the inner content of the textbox when clicked and reverting to the default version on blur. This code is currently ...

NodeJS threw an error: The call stack size has exceeded the maximum limit

My tool of choice is socket.io Error Encountered: We are facing a RangeError while calling `socket.disconnect()`; Please help resolve this issue. Thank you! ...

Transferring Visitor's Country Code Between Two Web Applications Using .NET Framework (ASP/MVC)

I'm currently working on developing an application that collects user information such as country, city, and IP address of the website they're visiting. This data is then sent to another web application of mine, which will be automatically update ...

Having trouble with flash messages in Node.js?

Could anyone shed some light on why the flash messages are not displaying properly in my situation? Here is how I'm attempting to utilize them: This snippet is from my app.js file: var express = require('express'); var app = express ...

Stealthy Google Recaptcha integrated with a dynamic AJAX form

My website includes an ajax form: <form id="my_form"> <input type="text" id="field1" /> <input type="submit" value="submit" /> </form> I also have this JavaScript code: document.getElementById("my_form").onsubmit = fu ...

Adjust the color of the text based on a conditional in react

I am looking for a way to select elements and change text color in my unordered list based on specific conditions. Below is an example of the structure I have: <div style={styles.passwordRules}> <ul style={styles.listOne}> <li style={ ...

Unable to clear input field after submitting form in AngularJS with Ionic framework

Something strange is happening. Whenever I try to clear the model in the controller, the input field that is bound to the model using ng-model does not get cleared when the form is submitted. Controller angular.module('starter.controllers', []) ...

Accessing files from various directories within my project

I'm working on a project with 2 sources and I need to import a file from MyProject into nest-project-payment. Can you please guide me on how to do this? Here is the current file structure of my project: https://i.stack.imgur.com/KGKnp.png I attempt ...

The issue arises when attempting to update the input of a child component within a reactive form during the OnInit lifecycle

My dilemma arises in working with data stored in the ngrx entity store, as it gets displayed in chunks based on pagination. The issue lies with rxjs somehow remembering the paging history. For instance, when I fetch the first page of data from the server, ...

Avoiding Vue Select from automatically highlighting the initial option: tips and tricks

Currently utilizing Vue Select as a typeahead feature that communicates with the server via AJAX. By default, the first option from the server response is highlighted like this: https://i.stack.imgur.com/jL6s0.png However, I prefer it to function simila ...