<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using services in an angular module in Integration, Extension &amp; APIs</title>
    <link>https://community.qlik.com/t5/Integration-Extension-APIs/Using-services-in-an-angular-module/m-p/34429#M537</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Solved my own problem. Can't say I fully understand what's going on here (particularly with modules), but you can create a service right on the qvangular object. Also, I noticed that in my temporary service above, I wasn't using constructor() so the console log &lt;SPAN style="color: #0000ff; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f8f8f8;"&gt;"Service constructor called" &lt;/SPAN&gt;wasn't actually being called. Here's some working code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_15236495606951053" jivemacro_uid="_15236495606951053"&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;let qvangular = window.require('qvangular');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;let angular = window.require('angular');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;//angular.module('root-module', [])&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;qvangular//.module&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;.service('myService', &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; class MyService { &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; constructor(){&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; this.hello = "hello";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; console.log("Service constructor called")&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; doThis(){&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; console.log("do this:", this, this.hello);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;qvangular.directive('temp',['myService', function(myService){&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; return {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; template: 'this works when I do not use module or a service',&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; restrict: 'E',&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; scope: {},&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; controller: ['$scope', function($scope){&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; myService.doThis();&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; console.log("in temp directive controller", myService);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; }]&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; };&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;}]);&lt;/SPAN&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Apr 2018 20:00:12 GMT</pubDate>
    <dc:creator>jonvitale</dc:creator>
    <dc:date>2018-04-13T20:00:12Z</dc:date>
    <item>
      <title>Using services in an angular module</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Using-services-in-an-angular-module/m-p/34428#M536</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all (and probably &lt;A href="https://community.qlik.com/qlik-users/5070"&gt;erik.wetterberg&lt;/A&gt;‌)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am really trying in my extension to use good angular practices, which means separating concerns and keeping too much logic out of controllers. As such, I am trying to use a service to do a lot of the heavy lifting (particularly interacting with the qlik engine).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I'm having difficulty configuring my code to make a service available to a custom directive. There appear to be two qlik angular objects floating around, and I'm not sure which to use. Using requirejs we can pull in "angular" or "qvangular". I have been successful adding a custom directive to qvangular and getting it to display in the template. But this code is not successful:&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_15236425244315905" jivemacro_uid="_15236425244315905"&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;let qvangular = window.require('qvangular');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;let angular = window.require('angular');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;console.log("both angulars", qvangular, angular);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;//angular.module('root-module', [])&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;qvangular.module&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;.service('myService', class MyService { MyService(){console.log("Service constructor called")}})&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;.directive('temp',['myService', function(myService){&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; return {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; template: 'this works when I do not use module or a service',&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; restrict: 'E',&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; scope: {},&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; controller: ['$scope', 'myService', function($scope, myService){&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; console.log("in temp directive controller", $scope, myService);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; }]&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; };&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;}]); &lt;/SPAN&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Error: [$injector:unpr] Unknown provider: myServiceProvider &amp;lt;- myService&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Within qvangular, module is an object, not a method for defining a new module. So, my assumption is that an extension uses a single module, which we can access with qvangular.module, and add services right to it. I tried to also use "angular" and define a new module with a service, but that doesn't seem to work (or allow a custom directive).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm also just generally interested in what "qvangular" represents and what "angular" represents. Here is the layout of each in chrome console (qvangular, then angular) with module uncollapsed:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/199601_Capture.PNG" style="height: 342px; width: 620px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any insights forthcoming.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Apr 2018 18:08:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Using-services-in-an-angular-module/m-p/34428#M536</guid>
      <dc:creator>jonvitale</dc:creator>
      <dc:date>2018-04-13T18:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using services in an angular module</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Using-services-in-an-angular-module/m-p/34429#M537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Solved my own problem. Can't say I fully understand what's going on here (particularly with modules), but you can create a service right on the qvangular object. Also, I noticed that in my temporary service above, I wasn't using constructor() so the console log &lt;SPAN style="color: #0000ff; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f8f8f8;"&gt;"Service constructor called" &lt;/SPAN&gt;wasn't actually being called. Here's some working code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_15236495606951053" jivemacro_uid="_15236495606951053"&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;let qvangular = window.require('qvangular');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;let angular = window.require('angular');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;//angular.module('root-module', [])&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;qvangular//.module&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;.service('myService', &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; class MyService { &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; constructor(){&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; this.hello = "hello";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; console.log("Service constructor called")&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; doThis(){&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; console.log("do this:", this, this.hello);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;qvangular.directive('temp',['myService', function(myService){&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; return {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; template: 'this works when I do not use module or a service',&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; restrict: 'E',&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; scope: {},&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; controller: ['$scope', function($scope){&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; myService.doThis();&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; console.log("in temp directive controller", myService);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; }]&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; };&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;}]);&lt;/SPAN&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Apr 2018 20:00:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Using-services-in-an-angular-module/m-p/34429#M537</guid>
      <dc:creator>jonvitale</dc:creator>
      <dc:date>2018-04-13T20:00:12Z</dc:date>
    </item>
  </channel>
</rss>

