1

I want to set default value of e.name to "ALL" using ng-init
Here is my TEMPLATE code :

<tr ng-repeat="e in employees" ng-init="employees[0] = 'ALL'">
   <td>{{ $index + 2}}</td>
   <td>{{ e.name}}</td>
   <button type="button" ng-click="select(employee)">
          Select
   </button>
   </td>
</tr>

DIRECTIVE link

scope.employees = EmployeeService.query();

Here I want to set default value of e.name to ALL before generating dynamic data
I am getting dynamic data properly in employees and {{ e.name}} from directive

but here I want to show ALL in same <td> before getting dynamic data

1 Answer 1

1

If you're just trying to display ALL before data is retrieved, you could consider using an or operator.

<tr ng-repeat="e in employees">
   <td>{{$index + 2}}</td>
   <td>{{e.name || 'ALL'}}</td>
   <button type="button" ng-click="select(employee)">
          Select
   </button>
   </td>
</tr>

However, if you actually need ALL to be a value, I would strongly suggest setting it to the default value where ever you model employees.

Sign up to request clarification or add additional context in comments.

7 Comments

I am getting error Error: [$parse:syntax] Syntax Error: Token ''ALL'' is not a valid identifier at column 19 of the expression [e.name | 'ALL'] starting at ['ALL'].
@ojuskulkarni Are you using two pipes? The error provided suggests that you are only using one. Please ensure you're using two pipes like the following: {{e.name || 'ALL'}}
Yes mistakenly I used single | pipe, but now I am using || it's good that I am not getting error but I it's not showing ALL at first position. ok and I updated my question, added $scope.employees so now how I set default value there ?
Then it sounds like e.name is already defined. I see you've edited your post to include more details. What does EmployeeService.query(); return by default?
It's giving all employee entries from database. and I am getting all entries properly here only the problem is before rendering all this dynamic entries I want to set default value so that when I don't want any employee entry that time it should be possible for me to select default value
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.