I tried hard to solve this but couldn't get a possible solution.
I am using 2 instances of a directive on the same page to set value of 2 text fields with different values. but when i select one the other also changes to the same value.
Any insights into this will be appreciated as I am stuck from a long time on this issue.
I tried ngModel Isolate scope and all...
whenever I change one value the other also gets affected.
I cut few of my code and created a [plunker] http://plnkr.co/edit/xwsrThvbVsIXPotRHc7o. But cant happen to make that work as well.
My Template
<input class="form-control" id="lovdat" name="lov" ng- dblclick="dblClick()" ng-keyup="keyUp($event)" ng-model="lovval.displayval"
type="text">
My Directive
var app = angular.module('plunker', ['LOVDirective']);
app.controller('MainCtrl', function($scope) {
$scope.officeMaster = {
officeId: "",
officeName: "",
company: "",
companyId: "",
officeManager: "",
officeManagerId: "",
officeLocation: "",
isactive: ""
};
$scope.lovvalemp = {
displayval: "",
dataval: ""
}
$scope.lovvalcomp = {
displayval: "",
dataval: ""
}
});
angular.module('LOVDirective', [])
.directive('Lov', [function() {
return {
scope: {
label: '@', // optional
changeCallback: '&',
lovval: '=info'
},
restrict: 'EA',
replace: true, // optional
templateUrl: 'template.html',
link: function(scope, element, attr, ctrl) {
scope.param = {
"LOVType": attr.gacLovType,
"LOVSearchString": "",
"LOVSearchCriteria": ""
};
scope.alertModalPopup = {};
scope.alertModalPopup.selectedItem = "";
scope.dblClick = function() {
selectdata();
};
scope.selectdata = function() {
// var entityGrid = $("#lovGrid").data("kendoGrid");
scope.lovval.displayval = attr.gacLovType + "Sherry";
scope.lovval.dataval = attr.gacLovType + "1";
lovval = scope.lovval;
// lovval.ngModel = scope.lovval.dataval;
//ngModel.$setViewValue(scope.lovval);
// $("#lovdat").val = scope.lovval.displayval;
// $('#lovPopup').modal('hide');
};
}
};
}]);
My Index.html
<div class="form-group">
<label class="control-label required" for="txthead">Manager</label>
<lov ng-model="officeMaster.officeManager" data-gac-lov-type="EMPLOV" info="lovvalemp"></lov>
</div>
<div class="form-group">
<label class="control-label required" for="txtoffice">Company</label>
<lov ng-model="officeMaster.company" data-gac-lov-type="CMPLOV" info="lovvalcomp"></lov>
</div>