I have a directive called iframely
and I it inside an ng-repeat
like this:
<iframely url="iterator.url"></iframely>
This just treats the value as the string "iterator.url"
, not the actual .url
value. To experiment, I just put in a URL directly:
<iframely url="https://soundcloud.com/braxe1/braxe-one-more-chance"></iframely>
Which gives me the Syntax Error: Token ':' is an unexpected token
error. The closest I've gotten to passing this value to the directive is:
<iframely url="'{{iterator.url}}'"></iframely> // note double and single quotes
This resolves the URL parameter of iterator
, but also passes it along with the ' '
single-quotes as part of the string.
EDIT: Also tried that without the single quotes.
<iframely url="{{iterator.url}}"></iframely>
And got Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{iterator.url}}] starting at [{iterator.url}}]
What is the correct way to do this?
EDIT2: Here is the code for the directive:
angular.module( 'iframely', [])
.directive( 'iframely', [ '$http', '$sce', function ( $http, $sce ) {
return {
replace: true,
restrict: "E",
scope: {
url: '='
},
template: '<div ng-bind-html="content"></div>',
link: function ( scope, element, attrs ) {
$http( {
url: 'http://localhost:8061/iframely',
method: 'GET',
params: {
url: attrs.url
}
})
.then( function ( result ) {
scope.content = $sce.trustAsHtml( result.data.html )
})
}
}
}])
In other examples we will look at Bash scripts that when executed fail with the “unexpected token” error. To fix the error in a single command it’s usually enough to add or remove some incorrect characters that cause the syntax error in the command.
The Syntax Error Near Unexpected Token is an error that’s Usually withstood from the existence of all system files. These frequent Windows errors are usually less difficult to repair.
The data contains URL and read that data and bind to table. '>' is an unexpected token. The expected token is '"' or '''. Line 1, position 50. Any Body can Please share solution to me.
There is a syntax error. The token ‘ then ‘ is unexpected. All good! Lesson 3: When you see a syntax error verify that you are using Bash loops or conditional constructs in the right way and you are not adding any statements that shouldn’t be there.
You must replace url: '='
By url: '@'
https://docs.angularjs.org/api/ng/service/$compile
Change your directive to be the following:
angular.module( 'iframely', [])
.directive( 'iframely', [ '$http', '$sce', function ( $http, $sce ) {
return {
replace: true,
restrict: "E",
scope: {
url: '@'
},
template: '<div ng-bind-html="content"></div>',
link: function ( scope, element, attrs ) {
$http( {
url: 'http://localhost:8061/iframely',
method: 'GET',
params: {
url: scope.url
}
})
.then( function ( result ) {
scope.content = $sce.trustAsHtml( result.data.html )
})
}
}
}])
Notice the '@' in the scope and the url: scope.url
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With