【发布时间】:2014-11-25 02:47:43
【问题描述】:
我正在尝试使用 Angular 指令修改嵌入对象。我很难让指令生效。
这是目标代码。
<object width="250" height="40">
<param name="movie" value="http://grooveshark.com/songWidget.swf">
<param name="wmode" value="window">
<param name="allowScriptAccess" value="always">
<param name="flashvars" value="hostname=cowbell.grooveshark.com&songIDs=26593443&style=metal&p=0">
<embed src="http://grooveshark.com/songWidget.swf" type="application/x-shockwave-flash" width="250"height="40"flashvars="hostname=cowbell.grooveshark.com&songIDs=26593443&style=metal&p=0" allowscriptaccess="always" wmode="window"/>
</object>
我想要做的是动态定义歌曲 ID。我试过了
<object width="250" height="40">
<param name="movie" value="http://grooveshark.com/songWidget.swf">
<param name="wmode" value="window">
<param name="allowScriptAccess" value="always">
<param name="flashvars"value="hostname=cowbell.grooveshark.com&songIDs=" + {{bpmSong[0].$id}} + "&style=metal&p=0">
<embed src="http://grooveshark.com/songWidget.swf" type="application/x-shockwave-flash"width="250"height="40"flashvars="hostname=cowbell.grooveshark.com&songIDs=" + {{bpmSong[0].$id}} + "&style=metal&p=0" allowscriptaccess="always" wmode="window"/>
</object>
基本上我有一个号码是{{bpmSong[0].$id}},我试图用它来定义为 SongID。
我认为指令是我需要的解决方案,但我无法让指令起作用。
非常感谢任何帮助。
从@JayMc 的回答中尝试更新。我还更改了 src,以便我没有收到语法错误。还是不行。
index.html
<body ng-app="GrooveApp">
<div ng-controller="MainCtrl">
<div class="col-md-12" id="radio">
<button class="btn-lg btn-danger" ng-click="count = count - 1" ng-init="count=0">Previous</button>
<flash-widget songID='{{bpmSong[0].$id}}' ></flash-widget>
<button class="btn-lg btn-danger" ng-click="count = count + 1">Next</button>
</div>
<div class="col-md-12">
{{bpmSong[count].$id}}
</div>
</div>
app.js
angular.module("GrooveApp", ["firebase"])
.controller("MainCtrl", function($scope, $firebase) {
var ref = new Firebase("/bpm_playlist");
var sync = $firebase(ref);
// create a synchronized array for use in our HTML code
$scope.bpmSong = sync.$asArray();
})
.directive('flashWidget', function(){
return {
restrict: 'E',
scope: {
width:'=',
height:'=',
src: '=',
songID: '='
},
template: '<object width="250" height="40">'+
'<param name="movie" value="http://grooveshark.com/songWidget.swf">'+
'<param name="wmode" value="window">'+
'<param name="allowScriptAccess" value="always">'+
'<param name="flashvars"value="hostname=cowbell.grooveshark.com&songIDs="{{songId}}"&style=metal&p=0">'+
'<embed src="http://grooveshark.com/songWidget.swf" type="application/x-shockwave-flash"width="250"height="40"flashvars="hostname=cowbell.grooveshark.com&songIDs="{{songId}}"&style=metal&p=0" allowscriptaccess="always" wmode="window"/>'+
'</object>'
}
});
【问题讨论】:
-
您忘记将
template:中的字符串与+连接 -
我做了,我移动了 src,我不再收到语法错误,但 Flash 播放器说没有歌曲
标签: javascript angularjs embed firebase