0

I am trying to load angular inline templates as follows:

<ng-include src="templateId"></ng-include>

Here is the inlined template:

<script type="text/ng-template" id="needs.html">
  <div class="form-group">
    <div class="col-lg-6">
      <div ng-repeat="need in needs" class="hidden-radios">
        <input type="radio" id="{{need}}" name="needs" ng-required="true" ng-model="advertisement.need" ng-value="need"/>
        <label for="{{need}}" class="col-lg-6">
          <span class="block-span">
            {{ need }}
          </span>
        </label>
      </div>
    </div>
  </div>
</script>

and the relevant portion from the controller:

 $scope.focusNeed = function(){
            console.log('focusNeed');
            $scope.templateId='needs.html';
        };

See codepen here: http://codepen.io/balteo/pen/ogBBXZ?editors=101

The issue I have is that the app tries to load the template by issuing request on the server instead of looking at the inline templates.

Can anyone please help?

1 Answer 1

1

That is because your template is out of scope. Place <script type="text/ng-template" id="needs.html"> inside ng-app and it will work.

In real world ng-app is on the body. Butin codepen you cannot do that. That is why you'd better use plunker.

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

1 Comment

Spot on! Thanks Sergey!

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.