Angularjs,我无法将变量传递给指令,为什么?

时间:2016-01-08 09:19:27

标签: javascript angularjs angularjs-directive

在我的模板中,我调用目录:

<div ng-controller="ProfileController as vm">
  {{vm.profile._id}} <!-- test ok! _id printing -->
  <wcr-requestbutton receiving-id="vm.profile._id"></wcr-requestbutton>
</div>

在我的目录中,我搜索receive-id:

function wcrRequestbutton() {
  var directive = {
    restrict: 'E',
    templateUrl: 'app/components/friendship/requestbutton/requestbutton.html',
    scope: {
      receivingId: '='
    },
    controller: requestBtnCtrl,
    controllerAs: 'vm',
    bindToController: true
  };

  return directive;
}

在我的控制器中,我尝试使用receiverId varaible:

function requestBtnCtrl(friendshipService){
    var vm=this;
    console.log('vm: ',vm); // console print: 'vm:  Object { receivingId: undefined }'
}

但是当我启动demo时,我的控制台打印出这个结果: vm:Object {receivingId:undefined}

为什么呢?可以帮帮我吗?

0 个答案:

没有答案