Nikhil Mohanan
Nikhil Mohanan

Reputation: 1260

ng-include throws [$parse:syntax] error

I am trying to give ng-include="'http://www.myxyzsite.com/assets/view/partial.html'".but it gaves error like

Syntax Error: Token ':' not a primary expression at column 5 of the expression [http://www.myxyzsite.com/assets/view/partial.html] starting at [http://www.myxyzsite.com/assets/view/partial.html].

Is it possible to use ng-include with absolute path?

Anybody know, what i am doing wrong?

Upvotes: 1

Views: 1297

Answers (3)

Sherin Green
Sherin Green

Reputation: 358

Please Avoid "http://www.myxyzsite.com/assets/view/" from your url just put partial.html only and run it and if it is not work then go to console and go to network section then in the left side you can see all resources(pages) including "partial.html" and select that resource and right side you can see the requested URL link then you can see the path and adjust your URL in code according to this.

Upvotes: -1

StepUp
StepUp

Reputation: 38199

You cannot include references into ng-include as it is not built-in with Angular.

But you could create your own directive that can do this. All what you should do is send off an http request to the provided url (assuming the server that the url references is implementing CORS)

You can make a service and use it within your controller to get the content once on initialization.

Update:

Include Cross Domains

By default you cannot include cross domains files, however it is possible to include files from other domains.

Add a whitelist of legal files and/or domains in the config function of your web application:

<body ng-app="yourApp">

<div ng-include="'http://www.website.no/angular_include.asp'"></div>

<script>
var app = angular.module('yourApp', [])
app.config(function($sceDelegateProvider) {
    $sceDelegateProvider.resourceUrlWhitelist([
        'http://www.website.no/**'
    ]);
});
</script>

</body>

Please, read this article.

Upvotes: 0

VadimB
VadimB

Reputation: 5711

You can use $templateCache object to place your live data into it and use ng-include after

// read page using get
$http.get('link-to-page', {cache:$templateCache});

And you can iclude this data after using ng-include directive

ng:include src="link-to-page"></ng:include>

Upvotes: 2

Related Questions