尝试使用双向数据绑定使用自定义code的指令来改变材料的MD-选定的选项卡 [英] Trying to change the material md-selected tab using custom code from directive using two way data binding

查看:157
本文介绍了尝试使用双向数据绑定使用自定义code的指令来改变材料的MD-选定的选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用code键更改标签,似乎无法找出错误。如果我们使用控制器改变变量,但是当我试图通过指令来绑定它的基本的东西的作品,它brokes。

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;
      };
    }
  };
});

您可以与codePEN错误查看工作code:的 HTTP://$c$cpen.io/piyushchauhan2011/pen/rVRqeV编辑= 101

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

的错误是:

推荐答案

修改 selectedTab =selectedTab选择标签=selectedTab 同时传递参数给你的指令。

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

请参阅该工作提琴: http://jsfiddle.net/2yd9u7b9/

这篇关于尝试使用双向数据绑定使用自定义code的指令来改变材料的MD-选定的选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆