javascript - Getting data from AngularJS to Silverlight -
i have spa built on angularjs in witch need display silverlight media player. need pass id number of selected media file silverlight app can fetch information needs play it. first tried using silverlight's initparams such:
<param name="initparams" runat="server" value="{{value}}"/> after failed attempted id url , set silverlight apps onload function this:
<script type="text/javascript"> var patharray = window.location.pathname.split('/'); var value = patharray[1]; var slctl = null; function pluginloaded(sender, args) { slctl = sender.gethost(); slctl.content.silverlightobject.setmediaid(value); } </script> but realized both value angularjs controller , url set after page had loaded. when silverlight app loaded didn't have correct information.
right think best way solve create angularjs directive creates silverlight application, since have access id.
am on right path here, easiest way solve problem?
edit: in 1 of first attempts attached som inline javacript function silverlights onload
<param name="onload" value="pluginloaded" /> that method called method on silverlight application passing in value.
slctl.content.silverlightobject.setmediaid(value); would possible call method angularjs? have create directive too, or controller? how should access silverlight object in controller/directive?
here final solution came with.
<div class="ui-helper-clearfix no-left-padding"> <form id="form1" runat="server" style="height: 500px"> <div id="silverlightcontrolhost" style="height: 500px"> <object id="mediaplayer_8" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="800" height="500"> <param name="source" value="../../../clientbin/mediaplayer.xap" /> <param name="onerror" value="onsilverlighterror" /> <param name="background" value="#f2f2f2" /> <param name="minruntimeversion" value="5.0.61118.0" /> <param name="autoupgrade" value="true" /> <param name="onload" value="pluginloaded" /> <a href="http://go.microsoft.com/fwlink/?linkid=149156&v=5.0.61118.0" style="text-decoration: none"> <img src="http://go.microsoft.com/fwlink/?linkuserid=161376" alt="get microsoft silverlight" style="border-style: none" /> </a> </object> <iframe id="_sl_historyframe" style="border: 0px; height: 0px; visibility: hidden; width: 0px;"></iframe> </div> </form> <script type="text/javascript"> var slctl = null; function pluginloaded(sender, args) { slctl = sender.gethost(); slctl.content.silverlightobject.setmediaid(@viewbag.currentmedia); } </script> key stuff is:
<param name="onload" value="pluginloaded" /> and
<script type="text/javascript"> var slctl = null; function pluginloaded(sender, args) { slctl = sender.gethost(); slctl.content.silverlightobject.setmediaid(@viewbag.currentmedia); } </script> and in silverlight app had
[scriptablemember] public void setmediaid(int mediaid) { _viewedmediaid = mediaid; _proxy.getmediaasync(_viewedmediaid); } hope helps.
Comments
Post a Comment