title: Calling C# function from AngularJs script in Xamarin Forms PCL Universal Windows Application
body: <p>I am developing a cross platform xamarin forms application. I have created a Portable Cross-Platform App, in which I am trying to open local HTML pages in webview. For calling C# function from Angularjs, I have implemented hybrid web view concepts.</p>
  
  <p>My Angularjs Function</p>
  
  <pre><code> $scope.SyncServerJobs = function () {
      //$scope.loadActList();
     window.CommInterface.syncServerJobs("");
  }
  </code></pre>
  
  <p>In My Universal Windows Project</p>
  
  <pre><code> public class HybridWebViewRenderer : ViewRenderer&lt;HybridWebView, Windows.UI.Xaml.Controls.WebView&gt;
  {
      public CommInterface communicator = new CommInterface();
  
      const string JavaScriptFunction = "function invokeCSharpAction(data){window.external.notify(data);}";
      const string SyncServerJobs = "function syncServerJobs(data){window.external.notify(data);}";
  
      protected override void OnElementChanged(ElementChangedEventArgs&lt;HybridWebView&gt; e)
      {
          base.OnElementChanged(e);
  
          if (Control == null)
          {
              var webView = new WebView();
              webView.Settings.IsJavaScriptEnabled = true;
              SetNativeControl(webView);
          }
          if (e.OldElement != null)
          {
              Control.NavigationStarting -= OnWebViewNavigationStarted;
              Control.NavigationCompleted -= OnWebViewNavigationCompleted;
              Control.ScriptNotify -= OnWebViewScriptNotify;
          }
          if (e.NewElement != null)
          {
              Control.NavigationStarting += OnWebViewNavigationStarted;
              Control.NavigationCompleted += OnWebViewNavigationCompleted;
              Control.ScriptNotify += OnWebViewScriptNotify;
              Control.Source = new Uri(string.Format("ms-appx-web:///Content//{0}", Element.Uri));
          }
      }
  
      private void OnWebViewNavigationStarted(WebView sender, WebViewNavigationStartingEventArgs args)
      {
          if (Control != null &amp;&amp; Element != null)
          {
              communicator = new CommInterface();
              Control.AddWebAllowedObject("CommInterface", communicator);
          }
      }
  
      async void OnWebViewNavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
      {
          if (args.IsSuccess)
          {
              // Inject JS script
              await Control.InvokeScriptAsync("eval", new[] { JavaScriptFunction });
              await Control.InvokeScriptAsync("eval", new[] { SyncServerJobs });
          }
      }
  
      void OnWebViewScriptNotify(object sender, NotifyEventArgs e)
      {
          Element.InvokeAction(e.Value);
      }
  }
  </code></pre>
  
  <p>My commInterface class</p>
  
  <pre><code> [AllowForWeb]
  public sealed class CommInterface
  {
      readonly WeakReference&lt;HybridWebViewRenderer&gt; hybridWebViewRenderer;
  
      public CommInterface()
      {
  
      }
  
      public void syncServerJobs(string data)
      {
          HybridWebViewRenderer hybridRenderer;
          if (hybridWebViewRenderer != null &amp;&amp; hybridWebViewRenderer.TryGetTarget(out hybridRenderer))
          {
              hybridRenderer.Element.SyncServerJobs(data);
          }
      }
  }
  </code></pre>
  
  <p>As like in Android project I am using CommInterface class to communicate with database class in Portable library. But in my Universal Windows project, I am not able to communicate with Csharp functions to run CSharp CRUD functions. How can I call the CSharp function from script?</p>