0

I'm trying to implement two way binding for custom directive in angularJs. Somehow its not working.

html file

<div ng-app='myApp'>Outside directive
  <input type='text' ng-model='outAttr'>{{outAttr}}</br>
  <div my-directive some-attr='outAttr'></div>
</div>

js file

var myApp = angular.module('myApp', []);

myApp.directive('myDirective', function () {
  return {
      restrict: 'A,
      replace: true,
      scope: {
        inAttr: '=someAttr';
      },
      template: "<div><input type='text' ng-model='inAttr'>\
                {{inAttr}}</div>"
     }
})

Somehow its not working. here is JSFiddle link. Can someone help me pointing out my mistake. Thanks.

1 Answer 1

1

Few syntax errors. The logic of your code is OK - jsFiddle

var myApp = angular.module('myApp', []);

myApp.directive('myDirective', function() {
    return {
        restrict: 'A', // missing '
        replace: true,
        scope: {
            inAttr: '=someAttr' // no ;
        },
        template: '<div><input type="text" ng-model="inAttr">{{inAttr}}</div>' // no break
    };
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. I think the ';' was the main issue there. While adding deleting I inadvertantly removed " ' " from restrict. My bad! Just now I got it working on fiddle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.