I'm new to angular 1x and I have some complicated display business logic
using multiple and nested ng-if statements that I had put into my web page,
just to get it working. It didn't pass the code review and the suggested
refactoring was to call a service to handle this. I created the service,
but was unable to call it directly from the view, which I understand is a
bad practice, so I put the call to the service in the controller as I
normally do and then called the $scope reference from the view similar to
what I have shown below:
I made the call to the service from a controller similar to this code:
$scope.functionName = serviceName.functionName($scope.paramOne);
and in the page I used:
<li>
<p>The value is: {{functionName}} </p>
//Then there is a call to a filter here to show another value.
</li>
When I tried to use this:
<!i ng-if="{{functionName}}">
I got this error:
Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the
expression ...
So is my working code a best practice or is there a better solution? I
still need to have some display logic for showing/hiding the <li> tag with
the value so this solution only cuts down on on the business logic in the
view, but now I don't have a way to show/hide the <li> tag since I'm not
using ng-if or rather couldn't get it to work with the function call inside
of it.
Thanks for any help,
James
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.