ashok kallagunta

ashok kallagunta

  • 1.8k
  • 42
  • 10.6k

Need Help : issue with 2 way binding in directive code.

May 27 2017 12:23 AM

Hi,

I am having issue with Angular custom directive code, I created sample code for 2 way binding between user control and main control, to do 2 way binding we use “=” , this is not performing in application, am I doing anything wrong?

I can able perform one way binding use “@”.

Below is my sample code.

Main CSHTM file code.

---------------------------------------------- 

<body ng-app="directivesexample">

<div ng-controller="homecontroller">

<h3>Main Controlh3>

<input type="text" name="name" ng-model="datamodel" /> {{datamodel}}<br />

<sample-directive edit-fld1="{{datamodel}}">sample-directive>

div>

body>

Below is my AngularJs code.

------------------------------------------------ 

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

obj.controller('homecontroller', function ($scope) {

$scope.datamodel = "sample data";

});

obj.directive('sampleDirective', function () {

var directive = {};

directive.restrict = "E";

directive.scope = {

editFld1: "="

};

directive.templateUrl = "usercontrol.html";

return directive;

});

Below is my directive(usercontrol) code.

----------------------------------------------------- 

<h3>User Controlh3>

<input type="text" name="name" ng-model="editFld1" /> {{editFld1}}

Kindly let me know, where I am doing mistake. I am using angular JS 1.6 plugin.


Answers (1)