Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
25
rated 0 times [  28] [ 3]  / answers: 1 / hits: 15918  / 8 Years ago, mon, october 24, 2016, 12:00:00

I have a Angular JS Application,



<div class=col-lg-12 ng-init=getTableData('{{URL::route('get_repair_category')}}')>


When Page loading the getTableData will execute, but I want to check a variable $rootScope.Dealer and switch the function name of initialization.



Eg : if $rootScope.Dealer value present I wanto execute the function named getDealerData



And If the value is not set need to execute the getTableData function.



How can I make this in anglar js template.



I just tried the ng-if, but its not working...


More From » angularjs

 Answers
3

You can use simple Javascript syntax in ng-init directive like this:



<div class=col-lg-12 ng-init=Dealer ? getDealerData('{{URL::route('get_repair_category')}}') : getTableData('{{URL::route('get_repair_category')}}')>


Here is a plnkr for you (I've changed backend route generation to text):
https://plnkr.co/edit/CJOMT0g50BCWa3j02rcS?p=preview


[#60300] Thursday, October 20, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breap

Total Points: 606
Total Questions: 96
Total Answers: 108

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
breap questions
Thu, Jun 24, 21, 00:00, 3 Years ago
Wed, Mar 18, 20, 00:00, 4 Years ago
Mon, Oct 7, 19, 00:00, 5 Years ago
;