0

I am using AngularJS 1.6.9 with AngularJS Material. What I want to do is to add a menu item basic usage. The problem is that it didn't work because my structure is different.

Documentation of material says (I never seen it before):

angular
  .module('menuDemoBasic', ['ngMaterial'])
  .config(function($mdIconProvider) {
    $mdIconProvider
      .iconSet("call", 'img/icons/sets/communication-icons.svg', 24)
      .iconSet("social", 'img/icons/sets/social-icons.svg', 24);
  })
  .controller('BasicDemoCtrl', function DemoCtrl($mdDialog) {

  ...

Html:

<div class="md-menu-demo" ng-controller="BasicDemoCtrl as ctrl" ng-cloak>
...

My controller's name is MainController and I don't want to change my syntax.

My js syntax is:

app.controller("MainController", ["$scope","$http","$rootScope", function($scope,$http,$rootScope){
...

How can I change the code, in order to not to change my structure of my Controller and play?

7
  • Add $mdDialog like this app.controller("MainController", ["$scope","$http","$rootScope", "$mdDialog", function($scope,$http,$rootScope, $mdDialog){ ... Commented Apr 9, 2018 at 18:53
  • and config part will be in app.js file Commented Apr 9, 2018 at 18:54
  • It was the first thing I tried. What about the Html? Commented Apr 9, 2018 at 18:56
  • 1
    <div class="md-menu-demo" ng-controller="MainController" ng-cloak> Commented Apr 9, 2018 at 18:57
  • 1
    I am putting answer here ..... Commented Apr 9, 2018 at 19:04

1 Answer 1

1

Include $mdDialog like

app.controller("MainController", ["$scope","$http","$rootScope", "$mdDialog", function($scope,$http,$rootScope, $mdDialog){
...  // order should be same.

And HTML

<div class="md-menu-demo" ng-controller="MainController" ng-cloak>
...
Sign up to request clarification or add additional context in comments.

4 Comments

Can you edit this? One more thing. How to replace in example ng-click="ctrl.redial($event)" the ctrl if I change into MainController?
It didn't work I just put ctrl again to work. Any other Ideas?
BasicDemoCtrl as ctrl , here ctrl is just an alias name ....not needed actually, but people use to make it short name
instead ctrl I check it with out it and with the whole name, nothing. Only with as ctrl works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.