javascript - function inside Controller inAngularjs -
i have 2 functions drag_drop , drag_start , inside these functions nedd data controller scope. code somthing
function drag_start(event) { event.datatransfer.dropeffect = "move"; event.datatransfer.setdata("text", event.target.getattribute('id')); } function drag_drop(event) { // here want use $scope controller }
controller code :
institutioncontroller.controller('institutioncontroller',function $http.get('/myresponses').then(function(myres) { $scope.myrps=myres.data; // want use $scope.myrps when drag , drop element inside div
html code :
ul(ng-hide="siwtchci",class="list-inline") li(ng-repeat="owninst in owninsts",draggable='true',ondragstart='drag_start(event)') a(class="btn btn-default btn-org" ,role="button") {{owninst.org.name}} #drop_zone(ondrop='drag_drop(event)', ondragover='return false')
the problem when put 2 functions inside controller html elements not draggable anymore
try declaring functions drag_start , drag_stop in scope. on html need specify below ondragstart="angular.element(document.getelementbyid('xyz')).scope().drag(event)" surely call drag method have defined in controller xyz represents id of html element dragged.