Trying to change the material md-selected tab using custom code from directive using two way data binding

末鹿安然 提交于 2019-12-24 05:23:04

问题


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:


回答1:


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

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



来源:https://stackoverflow.com/questions/31933813/trying-to-change-the-material-md-selected-tab-using-custom-code-from-directive-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!