I got list of countries, which will be populated in a dropdown box. I made it as a directive with list items.
And it on click of the country, the country name should be updated in $scope.selected which is defined in the controller.
Unfortunately i couldnt pass the data from the directive to the controller if the list item is clicked. How should i map it so that on click it updates the name and code.
Thanks
** Pasting the directive code **
myApp.directive("dropSelect",function(){
return{
restrict:'E',
scope : {
items : '=items',
selected:'=ngModel'
},
template:'<input type="text" ng-model="selected.name" placeholder="country">'+'<ul><li ng-repeat="item in items" ng-click="selectedCountry(item)">{{item.name}}<li></ul>',
link : function(){
},
controller:function($scope){
$scope.selectedCountry = function (item){
console.log(item);
$scope.selected.name = item.name
}
}
}
})
Edit 1:
adding @ symbol doesnt throw error but adding = symbol throws error
selected:'=ngModel' //throws error
selected:'@ngModel' //no error