AngularJS error message: 'Issue with 'MapCtrl' function - it is undefined'

Controllers.js
angular.module('starter.controllers',[])

.controller('AppCtrl',function($scope,$rootScope) {
    $rootScope.side_menu = document.getElementsByTagName("ion-side-menu")[0];

 $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromParams, toParams) {
if (toState.name != 'app.map') {
    $rootScope.side_menu.style.visibility = "visible";
}
});
})
.controller('MapCtrl',function($scope) {
    $rootScope.side_menu.style.visibility = "hidden";
})

New to Angular and Ionic. Have already browsed through similar questions on this issue. Thanks.

HTML

AppJS

Answer №1

Make sure to remove the ; in app.js when referencing the controller MapCtrl.

The correct format is 'MapCtrl', without the semicolon, as shown in the example:

    .state('app.map,{
      url:"/map",
      views: {
      'menuContent' :{
      templateUrl: "templates/map.html",
      controller: 'MapCtrl'
      }
     }
    })

P.S. Don't forget to inject $rootScope inside MapCtrl to prevent getting a

ReferenceError: $rootScope is not defined

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

unexpected behavior in vue-router transition

Currently, I am in the process of working on my personal website. For the frontend, I have been using Vue.js along with vue-router. Everything was functioning smoothly until today, as evidenced here: (you will need to scroll down or use the arrow key down ...

Maintaining Changes in Javascript and CSS

I have created a header that can slide in and out of view with a toggle function. However, I want the header to be in the down position by default, without requiring users to click the toggle every time a new page loads. I have limited knowledge of JavaScr ...

js/jquery Asynchronous Loading of Content Replaces Existing Page Content

I have encountered a problem that I am hoping someone can assist me with. Here is the issue: A partner of mine has given me a code to use on my website, which will display certain content that I am interested in. However, this content is only relevant to ...

"Can you provide instructions on placing a span within an image

I am trying to figure out how to insert a <span> into an <image>, similar to the effect on the page . However, I do not want this effect to occur on hover(), but rather on click(). My goal is to insert "data-title" into the <span> and hav ...

Exploring different methods to locate a random ID using XPATH, CSS path, and selector while conducting Selenium c# testing on a CMS tool

Issue: Hey there, I'm currently working on testing a CMS tool with selenium in C#. The problem I'm facing is finding a suitable selector for a small drop-down button due to the random generation of IDs for all selectors. Every time the script run ...

jQuery link disabling malfunctioning

I attempted to disable a hyperlink by checking a certain condition using an if statement in jQuery. After researching other solutions, I implemented the following code: if (discussionPointsSize == 0) { $('#discussionPointsLink').preventDefault ...

Tips for retrieving specific data from MongoDB using Node.js

Currently facing an issue working with Node.js, express, and mongodb when it comes to passing data between frontend and backend. Note: The code below represents middleware code for communication between frontend and backend. I have successfully retrieved ...

Unlimited height dialog overlay exclusive to Facebook

It seems like a crucial matter that needs attention. My dialog has an overlay with specific width settings as shown below: .ui-widget-overlay { width: 518px !important; } The height of the overlay will vary based on the page size controlled by JavaS ...

Take me to a different page through colorbox

Currently, I am facing an issue with my colorbox. My objective is to redirect to another page once a certain value has been validated using PHP. Below is the code snippet that I have attempted: if (isset($_POST['confirm'])) { echo "<scrip ...

Float over a specific line in a drawing

I am looking to develop a unique rating system using css, html, and potentially js : https://i.sstatic.net/pQP79.png My goal is for the user to hover over a specific section of a circular stroke and have it fill with a particular color, all while maintai ...

Is there a way to efficiently eliminate the button label from my dataset without causing any disruptions to my chart

I am looking to remove a specific label from my chart, but whenever I try to do so, it impacts the entire functionality. var ctx = document.getElementById("CountryChart");<br> var myChart = new Chart(ctx, {<br><br> type: 'bar&ap ...

Accessing JSON data in Node.js

I'm completely new to working with Node.js and I've been trying to figure out the best way to parse and query a JSON object. Recently, I came across this JSON object that I have loaded as a file: [ {"Key":"Accept","Values":["Application/x-www-fo ...

Conceal the div upon clicking anywhere on the page, except if a particular div is clicked

Whenever the user interacts with topic_tag_sug or any of its child elements, the div should remain visible. However, if the user clicks on any other element, topic_tag_sug should be hidden. HTML <input id='topic_tag' onblur="$('#topic_t ...

Guide to using Ajax to load a partial in Ruby on Rails

Whenever a search is triggered, I have a partial that needs to be loaded. This partial can take a significant amount of time to load, so I would prefer it to be loaded via Ajax after the page has fully loaded to avoid potential timeouts. Currently, my app ...

Tips on combining JSON objects into one

Trying to create a bar-chart with two separate functions that return data. Here's an example of the first function: $scope.data = { labels: ['Jan', 'Feb', 'Mar'], datasets: [ { label: 'My ...

No data returned when fetching with server-side rendering (SSR) requested

Seeking suggestions on how to implement loading items via API and server-side rendering. My SSR is set up using Express and Babel. Below is the component in question: class MyApp extends Component { constructor(props) { super(props) th ...

Issue with SwiperJS not completely filling the height of a div

My issue relates to using swiperJS with multiple images, as I'm struggling to make it take the full width and height of the containing div. Despite applying styling like this to my images: .swiper-slide img { width: 100%; height: 1 ...

Exposing the secrets of the Ajax module

Here is the code snippet I am working with: my.data = function () { var getAuth = function (userName, password) { var model = JSON.stringify({ "UserName": userName, "Password": password }); var result; $.ajax({ url: m ...

Creating Table Rows on-the-fly

Seeking assistance and guidance from the community, I have modified code from an online tutorial to allow users to dynamically add rows to a table when data is entered in the row above. However, I am facing an issue where I can only insert one additional ...

I am facing difficulty in loading my services in AngularJS

I am reaching out for assistance with a recurring issue I have encountered while working with AngularJS. Throughout my coding education, the greatest challenge for me has always been linking files together. However, in AngularJS, this task has become parti ...