1

I'm trying to figure out how to use function inside the src of ng-include but the code below doesn't work. I already tried using single quotation mark inside the double quotation mark but still not working.

TEMPLATE

<div ng-include src="{{templateUrl('tables/requestTable.html')}}"></div>

CONTROLLER

$scope.templateUrl = (url) => {
    return 'https://example.com/url';
}

1 Answer 1

2

ngInclude's src doesn't need curly braces. You can directly pass the function.

angular.module('myApp', [])
  .controller('test', function($scope) {
    $scope.templateUrl = function() {
      return 'url';
    }
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="myApp" ng-controller="test">
  <div ng-include src="templateUrl()"></div>

  <script type="text/ng-template" id="url">test template</script>
</div>

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

1 Comment

Thanks it works. my bad i forgot that you dont need to use curly braces on ng-

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.