Bind to ControllerAs Variables in Directives

时间:2015-07-08 15:39:26

标签: angularjs angularjs-directive angularjs-controlleras

Right, not an easy one to explain but I'll do my best.

I'm trying to make a directive that watches/uses data from an outer-directive (both currently elements).

If I don't use controllerAs syntax, this isn't an issue, as I can create a new isolated scope for my inner-directive picking the bits I want.

However, say for arguments sake, outer-directive has it's controllerAs 'vm' (as per normal) and has a property/value of 'name' - how would I then bind to it?

The obvious one was to try

scope : {
   name : '=vm.name'
}

But this just throws an error.

I've done a quick plnkr to try and explain:

http://plnkr.co/edit/VxUegDs7iweYVSHyAJKr?p=preview

I've tried various combinations of using

bindToController:true // from ng 1.3

and also assigning to and object

bindToController:{
    name : '='
} // ng 1.4

but no joy with either.

0 个答案:

没有答案