Tips for fixing the $injector problem in AngularJS

Recently, I started learning AngularJS and attempted to build a simple web page based on some tutorials. The page consists of two parts: one for user input using HTML and the other with JavaScript containing an if-else statement. However, I kept encountering an error in the console stating "[$injector:unpr]". index.html

<body ng-app="ngCribs" ng-controller="cribsController">
<div class="container">     
                <div class="row price-form-row" ng-if="!addListing">
                    <span class="input-group-addon">Min Price</span>
                    <select name="minPrice" id="minPrice" [ng-model]="priceInfo.min" class="form-control">
                      <option value="100000">$100,000</option>
                      <option value="200000">$200,000</option>
                      <option value="300000">$300,000</option>
              </select>
                  </div>          
                <span class="input-group-addon">Max Price</span>
                    <select name="maxPrice" id="maxPrice" ng-model="priceInfo.max" class="form-control">
                      <option value="100000">$100,000</option>
                      <option value="200000">$200,000</option>
                      <option value="300000">$300,000</option>
                     </select>
     <div class="container">
      <div class="col-sm-4" 
        ng-repeat="crib in cribs | cribsFilter:priceInfo | orderBy: '-id'">          
              <i class="glyphicon glyphicon-tag"></i> {{crib.price | currency}} <i class="glyphicon glyphicon-home"></i> {{crib.address}} 
                <span class="label label-primary label-sm">{{crib.type}}</span></div>             
 </body>
  <script src="app.js"></script>
  <script src="scripts/cribsFilter.js"></script>
</html>   

cribsFiler.js

angular
    .module('ngCribs')
    .filter('cribsFilter', function() {
    return function(listings, priceInfo) {
    var filtered = [];
    var min = priceInfo.min;
    var max = priceInfo.max;
     angular.forEach(listings, function(listing) {
      if(listing.price >= min && listing.price <= max) {
      filtered.push(listing);
                }
            });
       return filtered;
        }
    });

CribsController.js

angular
.module('ngCribs')
.controller('cribsController',function($scope, cribsFactory){

$scope.priceInfo ={
    min:0,
    max:1000000
}
$scope.cribs;
cribsFactory.getCribs().then(function(data){
    $scope.cribs = data.data;
});
(function(error){
    console.log(error);
});
});

App.js

angular.module('ngCribs',['ui.bootstrap']);

Answer №1

It's difficult to provide a definitive answer without reviewing your app.js, but based on the information provided, it seems like including a script tag to link to CribsController.js might be the solution you're looking for!

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

Steps for correctly invoking a function based on input value conditions

Lately, I've been developing a new website geared towards serving as a platform for various travel agencies to showcase their tour packages. The homepage features a functional filter section that enables users to search for offers based on different ...

External script implementing StratifiedJSIt is possible for an external script

Recently, I stumbled upon the amazing StratifiedJS library that offers many features I find essential. It functions flawlessly when implemented directly in my HTML file, like so: <script src="libraries/stratified.js"></script> <scr ...

tips for transferring a variable to a class function

I'm working on a JavaScript object that looks like this: var myObject = { initialize: function() { this.property1 = 'value 1', this.property2 = 'value 2' }, outer: { inner: { inner_ ...

guide to importing svg file with absolute path

I have been attempting to load SVG files from my LocalDrive using an absolute path. Despite successfully achieving this with a relative path, the same method does not work when utilizing an absolute path. <script> $(document).ready(functio ...

Input the date manually using the keyboard

I am currently utilizing the rc calendar package available at https://www.npmjs.com/package/rc-calendar When attempting to change the year from 2019 to 2018 by removing the "9," it works as expected. However, when trying to delete the entire date of 1/15/2 ...

Responsive DataTable in Bootstrap 5 automatically hides columns to ensure optimal display on different

Is it possible to create a responsive table using DataTable 1.13.4 and Bootstrap 5.2.3? I encountered an issue while testing the table on a mobile device (using Firefox, not an actual device) where a small horizontal scrollbar appears, causing some columns ...

Inaccurate results from MomentJS

When converting milliseconds to date and time using Moment, I am getting the correct output as expected. However, when converting the same date and time, it gives me incorrect output. I have utilized the unix and valueOf Moment methods. const moment = re ...

Issues with AngularJS Form Validation Functionality Detected in Google Chrome

I'm facing an issue with angularjs form validation not working properly in Chrome. Here's a simple demonstration on a plunker that highlights the problem. When non-numeric data is entered into the box and the button is clicked, Chrome still indic ...

What is the best way to include numerous attributes to an element using JavaScript?

Attributes can be included within a string in the following format: let attr = ' min="0" step="5" max="100" '; or let attr = ' min="2019-12-25T19:30" '; and so on. Is there a function available ...

The 'exhaustive-deps' warning constantly insists on requiring the complete 'props' object instead of accepting individual 'props' methods as dependencies

This particular issue is regarding the eslint-plugin-react-hooks. While working in CodeSanbox with a React Sandbox, I noticed that I can use individual properties of the props object as dependencies for the useEffect hook: For instance, consider Example ...

Retrieve JSON object from dropdown menu

I need to retrieve the object name from a dropdown menu when an item is selected. How can I access the object from the event itemSelect? Thank you for your attention. View Dropdown Menu XML code: <core:FragmentDefinition xmlns="sap.m" xmlns:c ...

Using NodeJS and EJS to Display MySQL Query Results

I am currently working on a project where I need to display data retrieved from a MySQL query in an HTML table. However, when I attempt to do so, I encounter the following output: [object Object],[object Object],[object Object],[object Object],[object Obj ...

Automated system is responsible for flagging and disabling comments

We are facing a puzzling issue at the moment. Our comments form allows users to submit their thoughts on news articles, and each submission is immediately accepted and displayed on the same page. Within each comment, there is a link that enables users to ...

Leaflet.js obscuring visibility of SVG control

I am currently working with Leaflet 0.7.1 and I am looking to create a radial menu (similar to openstreetmap's iD editor) using d3 and display it on top of the map. I have come across some examples that use Leaflet's overlayPane to append the svg ...

Using the increment operator within a for loop in JavaScript

this code snippet causes an endless loop for (let i = 0; ++i;) { console.log(i) } the one that follows doesn't even run, why is that? for (let i = 0; i++;) { console.log(i) } I want a thorough understanding of this concept ...

Tips and tricks for seamlessly aligning a specific section of your webpage to ensure it scrolls smoothly into view

My codes are not being centered when I use smooth scrolling on a specific section of a Bootstrap carousel template. Is there an easier way to achieve this? The explanation in a post from six years ago didn't help much. Here are my codes and screenshot ...

Converting JSON formatting from Object to Array: A Comprehensive Guide

Encountering another issue with changing the JSON array output. Struggling to figure out why it's not rendering the other files. Providing a clearer explanation below: In my code snippet, when I use data[name] = {, each return name is rendered into ...

What is the best way to save data from a jQuery plugin to a database using ASP .NET MVC?

I have a jQuery plugin called "Slider" that displays the current price of an item. I would like to enhance it by allowing users to change prices using the jQuery slider and update them in the database. Here is the model: public class Item { public in ...

Ways to conceal components upon clicking a different element

Struggling to make this jQuery function properly. I have a form with all fields contained in a div.form-group. The subscribe button is identified by the id subscribe. I'm aiming to hide the form fields when clicked, but my JavaScript doesn't see ...

How to pass a method from a child component to a parent component in Vue.js

Does anyone know how to pass a function from the child component to the parent component? I have a modal in the parent component with cancel and submit buttons. When either button is clicked, I want to close the child component. I tried setting "show" in t ...