newb newb - 1 year ago 94
AngularJS Question

How to call a scope function from another one angularjs?

I have a table filled with data;
I have a button to delete a row,
and I have input fields that show data from the selected row from table.

First I have to select that row...then the input fields

filled with the data from that same row....once I've done it, I can press delete...and the row is deleted...and the row below that deleted row is now selected...(which I can change not to be)...but the old values from the deleted row are still in the input fields...

Now I have to do something...2 options:

  1. set the selected row to null, and clear all the input fields...(which I have no idea how to do it...)

  2. use the new selected row and fill its data into the input fields...witch is in my opinion the better way to go...

So please help me, here is the code:

In my html file I have this:

<input ng-model="">
<input ng-model="student.firstname">
<p>Last Name</p>
<input ng-model="student.lastname">

<button ng-click="deleteStudent(student)">Delete Student</button>

<table name="tableStud" arrow-selector>

<td>First Name</td>
<td>Last Name</td>

<tr ng-repeat="student in result"
ng-class="{'selected':$index == selectedRow}"
<td>{{ }}</td>
<td>{{ student.firstname }}</td>
<td>{{ student.lastname }}</td>
<td>{{ student.mestorodjenja.ime }}</td>



I have a controler....with this:

$scope.deleteStudent = function(student) {
student).success(function(data) {
$scope.result.splice($scope.selectedRow, 1);



$scope.selectedRow = null;

$scope.setSelected = function(student, index) {
$scope.student = student;
$scope.selectedRow = index;

Answer Source

You could update the student after delete:

$scope.result.splice($scope.selectedRow, 1);
$scope.student = $scope.result[0]; 

Or if you want update just a few attributes, for example firstname: $scope.student.firstname = $scope.result[0].firstname;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download