I have a SPA built on AngularJS in witch I need to display a Silverlight media player. I need to pass the id number of the currently selected media file to the Silverlight app so it can fetch the information it needs to play it. First I tried using Silverlight's initParams as such:
<param name="initParams" runat="server" value="{{value}}"/>
After that failed I attempted to get the id from the URL and set it from the Silverlight apps onLoad function like 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 I quickly realized that both the value from the AngularJS controller and the URL where set after the page had loaded. So when the Silverlight app loaded it didn't have the correct information.
Right now I think that the best way to solve this would be to create a AngularJS directive that creates the Silverlight application, since that will have access to the id.
Am I on the right path here, what would be the easiest way to solve this problem?
Edit: In one of my first attempts I attached som inline javacript function to Silverlights OnLoad
<param name="onLoad" value="pluginLoaded" />
That method then called a method on the Silverlight application passing in the value.
slCtl.Content.SilverlightObject.SetMediaId(value);
Would it be possible to call this method from AngularJS? Would I have to create a directive for this too, or could I do it from the controller? How should I access to the Silverlight object in my controller/directive?