toggle visibility of a div using AngularJS

Struggling to hide/show a div using AngularJS, I have gone through multiple tutorials with no success. Finally opted for the code snippet mentioned in this link, but still facing issues.

Can anyone assist me in identifying the problem?

PS: Using angular 1.6.3

<html data-ng-app="crm">
<head>
  <title>Product Form</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
   ............
  <style type="text/css"> 
  .animate-show-hide.ng-hide {
    opacity: 0;
  }
  .animate-show-hide.ng-hide-add,
  .animate-show-hide.ng-hide-remove {
    transition: all linear 0.5s;
  }
  .check-element {
    border: 1px solid black;
    opacity: 1;
    padding: 10px;
  }
  </style>

  <script type="text/javascript">
  it('should check ngHide', function() {
  var checkbox = element(by.model('checked'));
  var checkElem = element(by.css('.check-element'));
  expect(checkElem.isDisplayed()).toBe(true);
  checkbox.click();
  expect(checkElem.isDisplayed()).toBe(false);
  });
  </script>
</head>
<body data-ng-controller="ProductController">

  <div class="col-md-8 col-sm-8 col-xs-8" style="position: absolute;top:0;bottom: 0;left: 0;right: 0;margin: auto;">

  <div class="panel panel-info spacer"><!-- <button type="button" class="close" data-dismiss="alert">x</button> -->
  <div class="panel-heading"><input type="checkbox" data-ng-model="checked" aria-label="Toggle ngHide"/><b> Product Form</b></div>
  <div class="panel-body">

   <div class="check-element animate-show-hide" data-ng-hide="checked">
   <form class="form-horizontal" name="prodForm" novalidate>
      <div class="form-group">
        .....
      </div>
        ....
   </form>
   </div>
   </div>
   </div>
   </div>

<script type="text/javascript" src="angular/angular.min.js"></script>
<script type="text/javascript" src="angular/angular-sanitize.min.js">   </script>
<script type="text/javascript" src="angular/angular-animate.js"></script>
</body>
</html>

Answer №1

If you are facing an issue where the module and controller are not being created, follow these steps. Start by creating a new file and adding the following code to it:

(function() {
  angular.module('crm',[])
         .controller('ProductController', ProductController)

  ProductController.$inject = ['$scope'];
  function ProductController($scope) {

  }
})();

Don't forget to inject this code into your HTML:

<script src="script.js"></script>

You can also check out the Plnkr example for reference:

https://plnkr.co/edit/sytU3IMgSpHreVlEDzOR?p=preview

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

When the div is loaded, automatically navigate to the crucial li element within it, such as the one with the class "import

Welcome to my first webpage: <html> <head> <script type="text/javascript" src="js/jquery.min.js"></script> </head> <body> <div id="comment"></div> <script type="text/ja ...

Blending ASP.NET Core 2.0 Razor with Angular 4 for a Dynamic Web Experience

I am currently running an application on ASP.NET Core 2.0 with the Razor Engine (.cshtml) and I am interested in integrating Angular 4 to improve data binding from AJAX calls, moving away from traditional jQuery methods. What are the necessary steps I need ...

Could the issue at hand possibly stem from the fact that the router isn't fully operational? It appears that router.query

Having trouble retrieving the parameters from the URL using router.query. I've tried various approaches but keep getting an undefined result. It seems like I'm on the right track, though. Highlighted query param in yellow... https://i.stack.img ...

Conceal the legend in Highcharts using Python script with Django

Need some assistance with a Django and Highcharts.js project I'm working on. Objective: hide the legend in a Highcharts chart from my views.py script. In my views.py file, I've successfully plotted various charts but struggling to hide the lege ...

Is there a way to extract information from an uploaded file in JavaScript without having to actually submit the file?

Looking for a way to extract data from a user uploaded file using Javascript without page submission? The goal is to process this data to provide additional options in a form on the same page. Any assistance with this would be highly appreciated. ...

Recognizing mouse and keyboard inputs within an Angular application when using ng-repeat

In my application, I am dynamically generating a series of spans using ng-repeat, with each span having a unique id (e.g. span-{{$index}}). Now, I am looking to implement the following functionality: When clicking on a span, I want to copy the id of that ...

Google Maps API now offers the ability to generate directions with up to 500 waypoints

I am facing a challenge with displaying a route on Google Maps using an array of 500 waypoints extracted from a GPS route. Google Maps is unable to create a direction or route with more than 23 waypoints, making it difficult to replicate the original GPS ...

I need clarification on some basic concepts about ajax - Can you help?

Could someone please assist me in clarifying a concept? Currently, I am utilizing the colorbox plugin to load an external html snippet (which is functioning correctly). However, my jquery selectors are unable to detect the newly loaded html. Is this the co ...

Illustrating a fresh DOM element with intro.js

I am currently utilizing intro.js to create a virtual 'tour' for my website. As I aim to provide a highly interactive experience for users, I have enabled the ability for them to engage with highlighted DOM elements at different points in the tou ...

Employ the faker.js library to automatically create a form within casperjs environment

When using Casperjs to fill and submit forms, it is necessary to manually input the data each time. On the other hand, Faker.js can generate fake data that can be used in forms. The question then arises - how can these two be combined effectively? Consider ...

Determining the Last Modified Date for a Sitemap using Javascript

I am trying to replicate the date format shown within <lastmod></lastmod> tags in a sitemap.xml file. How can I do this? The desired output is as follows: <lastmod>2016-01-21EEST18:01:18+03:00</lastmod> It appears that 'EEST ...

Attempting to showcase information on the Angular frontend

When attempting to retrieve the Street name, I am seeing [object Object]. What is the optimal approach for displaying JSON data on the client side? I managed to display a street name but struggled with other components. How can I access the other elements ...

Error with the jQuery scrolling plugin

Currently, the script is set up this way: jQuery(document).ready(function(){ var windheight = jQuery(window).height(); var windTop = jQuery(window).scrollTop(); var windbottom = windheight + windTop ; jQuery.fn.revealOnScroll = function(){ return this.e ...

Challenge: Issue with ng-required in Angular when using a custom directive

I am currently utilizing Angularjs version 1.5 for input validation within my form. The use of ng-required is essential for validating all required inputs. Nevertheless, I am encountering an issue with a custom directive that generates a combo box. This ...

Combining Rails 4 with coffeescript while encountering an issue with the jQuery sortable detatch functionality

Currently, I am using Ruby on Rails 4 along with the jquery-ui-rails gem. Within my application, there are certain lists that have a sortable jQuery function implemented. $ -> $('#projects').sortable handle: '.handle' ...

Utilizing AngularJS: Binding stateParams value to custom data within state objects

Following the guidelines here, I am setting a page title in my state object. $stateProvider .state('project', { url: '/projects/:origin/:owner/:name', template: '<project></project>', data : { pageTi ...

Guidelines for redirecting an on-click action to navigate to a link rather than entering text

Using the AJAX Live Search PDO feature, I made a modification to have the displayed words link to their respective URLs. However, clicking on the table does not redirect to the link but instead inputs the text. I am looking for a way to make the entire row ...

Client-Specific User Portal

Looking for some support on the back end of things. We are in the process of creating a portal where users will be directed to their specific landing pages upon logging in, providing access to files they have signed up for. Our team is exploring the use ...

jQuery event.preventDefault not functioning as expected

I am attempting to use jQuery's preventDefault() method, but when I submit the form, it still displays the default behavior and reloads the page. Here is the code from index.html: <body> <script src="/socket.io/socket.io.js"></script& ...

JavaScript Function to Convert JSON Data into an Excel File Download

I am looking for help with converting JSON data received from an AJAX POST Request into an Excel file (not CSV) for download on a button click. The JSON Data may contain blank values and missing fields for each JSON row. I have attempted to achieve this o ...