That doesn't work because that isn't where you reference what property you 
want to bind to. If you wanted (in your example) 'myObject' to be bound to 
'myObject.myProp' you would do it like so:

In your HTML:
<my-directive my-prop="myObject.myProp"></my-directive>

and your directive declaration (pretty much exactly what you have):

.directive("myDirective", [function() {
        return {
            restrict: "E",
            scope: {
                myProp: "=" // This works
            },
            link: function (scope, element, attrs) {
                console.log(scope.myProp); // this will be the value of 
myObject.myProp
            },
            templateUrl: "blablah/blah.html"
        };
    }])

What you have as the key in your scope object is just what you want the 
bound variable to be called in your directive scope. It has nothing to do 
with the variable in the parent scope is called. That bit is managed by 
whatever you pass into the directive attribute in your HTML.

Does that explain it a bit better?

On Wednesday, 15 January 2014 17:05:18 UTC+13, warish wrote:
>
> I understand that, what I am talking about is the 2 way binding using the 
> "=" sign when declaring an isolate scope in a directive. I left out all the 
> other code to make it simpler, sorry about the confusion.
>
> .directive("myDirective", [function() {
>         return {
>             restrict: "E",
>             scope: {
>                 myObject: "=", // This works
>                 'myObject.myProp': "=" // This does not, would like to 
> create the binding with just myProp and not the whole myObject
>             },
>             link: function (scope, element, attrs) {
>
>             },
>             templateUrl: "blablah/blah.html"
>         };
>     }])
>
> On Tuesday, January 14, 2014 7:37:09 PM UTC-8, Sander Elias wrote:
>>
>> Hi Warish,
>>
>> This is how javascript works! Nothing angular can do about that.
>> Still, this is working, however, not the way you think.
>> If you want access to the property, you need to do something like this: 
>> scope['myObject.myProperty'] in your code.
>> This is called a string 
>> literal<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Values,_variables,_and_literals#String_literals>.
>>  
>> String literals are valid as property names for objects,
>>
>> Regards
>> Sander
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to