Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

ng-click not working with md-button unless function is attached to $scope #5990

Closed
Marabyte opened this issue Nov 30, 2015 · 2 comments
Closed

Comments

@Marabyte
Copy link

When binding an object directly to a controller ng-click doesn't work with ng-button ie:

app.controller('ConfigCtrl', function () {
  var config = this;   
  config.nextTab = function (){
    console.log('Doesn't work');
  };
});
<md-button class="md-raised md-cornered md-primary" ng-click="config.nextTab()">Next</md-button>

But this works :

app.controller('ConfigCtrl', function ($scope) {
  $scope.nextTab = function (){
    console.log('Doesn't work');
  };
});
<md-button class="md-raised md-cornered md-primary" ng-click="nextTab()">Next</md-button>

Am I missing something obvious?

@devversion
Copy link
Member

That's the behavior of AngularJS.

If you want to use the nextTab Function without using $scope you should provide a variable name for your controller.

ng-controller="ConfigCtrl as config"

and then you can use your this.nextTab function as followed -> config.nextTab()

Take a look at http://codetunnel.io/angularjs-controller-as-or-scope/

@Marabyte
Copy link
Author

Marabyte commented Dec 1, 2015

Arrghhh.. stupid typo was to blame..

@Marabyte Marabyte closed this as completed Dec 1, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants