Trying to change the material md-selected tab usin

2019-07-08 14:13发布

I'm trying to change the tab using code and can't seem to figure out the error. The basic thing works if we use the controller to change the variable but when I try to bind it through directive, it brokes.

var app = angular.module('MyApp', ['ngMaterial']);
app.controller('HelloCtrl', function($scope) {
  $scope.selectedTab = 0;
});
app.directive('something', function() {
  return {
    restrict: 'E',
    template: '<div ng-click="changeNavigation()">Change Navigation</div>',
    scope: {
      selectedTab: '='
    },
    controller: function($scope) {
      $scope.changeNavigation = function() {
        console.log('Hello World');
        $scope.selectedTab = 2;
      };
    }
  };
});

You can view the working code with error on codepen: http://codepen.io/piyushchauhan2011/pen/rVRqeV?editors=101

The error is: Error for md-tabs

1条回答
该账号已被封号
2楼-- · 2019-07-08 15:04

Change selectedTab="selectedTab" to selected-tab="selectedTab" while passing parameter to your directive.

See this working fiddle: http://jsfiddle.net/2yd9u7b9/

查看更多
登录 后发表回答