Okay, this is really bugging me. I have a directive with isolate scope, using the controllerAs
syntax and bindToController
:
function exampleDirectiveFactory() {
var bindings = {
foo: '=',
bar: '@'
}
return {
bindToController: true,
controller : 'ExampleController',
controllerAs : 'vm',
scope : bindings,
template : 'foo = {{ vm.foo }}<br />bar = {{ vm.bar }}'
};
}
Assuming a usage like this:
<example foo="FOO" bar="BAR"></example>
...I expect the value of vm.foo
to be two-way bound to the value of the foo
attribute. Instead, it is undefined
.
The value of vm.bar
is equal to the attribute value bar
of the HTML element, which I expect.
When I try to change the value of vm.bar
using a filter, no change persists.
When I store the filtered value of vm.bar
to a new variable, vm.baz
, that works as expected.
So my question has two parts:
A) Why is the value of vm.foo
undefined when using '='
?
B) Why can't I change the value of vm.bar
in the scope of the controller, even if that change does not propagate to the HTML element attribute (which it shouldn't, because I'm using '@'
)?