Noa*_*oah 12 angularjs angular-directive
我有一个调用的指令iframely,我在里面ng-repeat这样:
<iframely url="iterator.url"></iframely>
Run Code Online (Sandbox Code Playgroud)
这只是将值视为字符串"iterator.url",而不是实际.url值.为了实验,我直接输入了一个URL:
<iframely url="https://soundcloud.com/braxe1/braxe-one-more-chance"></iframely>
Run Code Online (Sandbox Code Playgroud)
这给了我Syntax Error: Token ':' is an unexpected token错误.我最接近将此值传递给指令的是:
<iframely url="'{{iterator.url}}'"></iframely> // note double and single quotes
Run Code Online (Sandbox Code Playgroud)
这解析了URL参数iterator,但也将它与' '单引号一起作为字符串的一部分传递.
编辑:也尝试没有单引号.
<iframely url="{{iterator.url}}"></iframely>
Run Code Online (Sandbox Code Playgroud)
得到了 Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{iterator.url}}] starting at [{iterator.url}}]
这样做的正确方法是什么?
EDIT2:这是该指令的代码:
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 )
})
}
}
}])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23175 次 |
| 最近记录: |