Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal unknown provider #2247

Closed
1 task done
hopeworkscamden opened this issue Sep 20, 2016 · 13 comments
Closed
1 task done

Modal unknown provider #2247

hopeworkscamden opened this issue Sep 20, 2016 · 13 comments

Comments

@hopeworkscamden
Copy link

hopeworkscamden commented Sep 20, 2016

  • I understand that GitHub issues are not for tech support, but for questions specific to this generator, bug reports, and feature requests.
Item Version
generator-angular-fullstack 4.0.4
Node 5.4.0
npm 3.10.7
Operating System cloud9
Item Answer
Transpiler Babel
Markup HTML
CSS SCSS
Router ui-router
Client Tests Mocha
DB MongoDB
Auth Y

I cannot figure out why the Modal service injection is not working. I have added it as a dependency to the app.js and as well have added the dependency to the controller which I would like to use it from. Very desperate to get this working and appreciate anyone who can help me figure this out.

app.js

import _Auth from '../components/auth/auth.module';
import account from './account';
import admin from './admin';
import navbar from '../components/navbar/navbar.component';
import footer from '../components/footer/footer.component';
import main from './main/main.component';
import constants from './app.constants';
import util from '../components/util/util.module';
import socket from '../components/socket/socket.service';
import modal from '../components/modal/modal.service';

import './app.scss';

angular.module('camdenfirstApp', [ngCookies, ngResource, ngSanitize, 'btford.socket-io', uiRouter,
    uiBootstrap, modal, _Auth, account, admin, navbar, footer, main, constants, socket, util, 'leaflet-directive'
  ])
  .config(routeConfig)
  .run(function($rootScope, $location, Auth) {
    'ngInject';
    // Redirect to login if route requires auth and you're not logged in

controller trying to use the Modal

import angular from 'angular';
import uiRouter from 'angular-ui-router';
import routing from './main.routes';

export class MainController {
  $http;
  socket;
  Modal;
  awesomeThings = [];
  newThing = '';
  camden = {autoDiscover:true};
  locFound = false;

  /*@ngInject*/
  constructor($http, $scope, socket, Modal) {
    this.Modal = Modal;
    this.$http = $http;
    this.socket = socket;

    $scope.$on('$destroy', function() {
      socket.unsyncUpdates('thing');
    });

    $scope.delete = this.Modal.confirm.delete()('asdf');

    $scope.events = { // or just {} //all events
                        markers:{
                          enable: [ 'dragend' ]
                          //logic: 'emit'
                        }
                    }

    $scope.camden = {autoDiscover:true};

     $scope.$on('leafletDirectiveMap.locationfound', function(event){
        $scope.eventDetected = "ZoomStart";
         var instancePosition = {
                            lat: $scope.camden.lat,
                            lng: $scope.camden.lng,
                            focus: true,
                            message: "Drag to Flooding Instance",
                            draggable: true
                        };

       $scope.markers = {
                        instancePosition: angular.copy(instancePosition)
                      }
    });

    $scope.$on("leafletDirectiveMarker.dragend", function(event, args){
                $scope.camden.lat = args.model.lat;
                $scope.camden.lng = args.model.lng;
                $scope.markers.instancePosition.lat = args.model.lat;
                $scope.markers.instancePosition.lng = args.model.lng;
            });

  }


  $onInit() {
    this.$http.get('/api/things')
      .then(response => {
        this.awesomeThings = response.data;
        this.socket.syncUpdates('thing', this.awesomeThings);
      });
  }


  addThing() {
    if(this.newThing) {
      this.$http.post('/api/things', {
        name: this.newThing
      });
      this.newThing = '';
    }
  }

  deleteThing(thing) {
    this.$http.delete('/api/things/' + thing._id);
  }
}

export default angular.module('camdenfirstApp.main', [uiRouter])
  .config(routing)
  .component('main', {
    template: require('./main.html'),
    controller: MainController
  })
  .name;

EDIT: if you;d like to see the project itself you can find it here: https://camden-first-hopeworks.c9users.io:8081/

@Awk34
Copy link
Member

Awk34 commented Sep 20, 2016

Please surround your different code blocks with triple ticks (```). Your code is quite hard to read as-is.

@hopeworkscamden
Copy link
Author

@Awk34 sorry about that, I have updated

@Awk34
Copy link
Member

Awk34 commented Sep 20, 2016

Can you provide a full stack trace as well?

@hopeworkscamden
Copy link
Author

here is the full error that occurs

angular.js:13920ReferenceError: Modal is not defined
at new MainController (https://camden-first-hopeworks.c9users.io:8081/app.bundle.js:1143:19)
at Object.invoke (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:4845:20)
at $controllerInit (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:10481:35)
at nodeLinkFn (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:9390:35)
at compositeLinkFn (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:8747:14)
at publicLinkFn (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:8627:31)
at Object. (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:38087:10)
at https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:1374:19
at invokeLinkFn (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:10061:10)
at nodeLinkFn (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:9462:12)
at compositeLinkFn (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:8747:14)
at publicLinkFn (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:8627:31)
at lazyCompilation (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:8971:26)
at updateView (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:38005:24)
at https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:37954:12
at Scope.$broadcast (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:18132:29)
at https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:37335:23
at processQueue (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:16510:29)
at https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:16526:28
at Scope.$eval (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:17809:29)
at Scope.$digest (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:17622:32)
at Scope.$apply (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:17917:25)
at bootstrapApply (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:1888:16)
at Object.invoke (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:4845:20)
at doBootstrap (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:1886:15)
at Object.bootstrap (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:1906:13)
at https://camden-first-hopeworks.c9users.io:8081/app.bundle.js:93:22
at HTMLDocument.trigger (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:3334:8)
at defaultHandlerWrapper (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:3624:12)
at HTMLDocument.eventHandler (https://camden-first-hopeworks.c9users.io:8081/vendor.bundle.js:3612:10)

@thedewpoint
Copy link

Can you post what's in modal.service? You're expecting the import to provide you a module name but I'm not sure that's what you're importing

@hopeworkscamden
Copy link
Author

'use strict';

import angular from 'angular';

export function Modal($rootScope, $uibModal) {
  /**
   * Opens a modal
   * @param  {Object} scope      - an object to be merged with modal's scope
   * @param  {String} modalClass - (optional) class(es) to be applied to the modal
   * @return {Object}            - the instance $uibModal.open() returns
   */
  function openModal(scope = {}, modalClass = 'modal-default') {
    var modalScope = $rootScope.$new();

    angular.extend(modalScope, scope);

    return $uibModal.open({
      template: require('./modal.html'),
      windowClass: modalClass,
      scope: modalScope
    });
  }

  // Public API here
  return {

    /* Confirmation modals */
    confirm: {

      /**
       * Create a function to open a delete confirmation modal (ex. ng-click='myModalFn(name, arg1, arg2...)')
       * @param  {Function} del - callback, ran when delete is confirmed
       * @return {Function}     - the function to open the modal (ex. myModalFn)
       */
      delete(del = angular.noop) {
        /**
         * Open a delete confirmation modal
         * @param  {String} name   - name or info to show on modal
         * @param  {All}           - any additional args are passed straight to del callback
         */
        return function() {
          var args = Array.prototype.slice.call(arguments);
          var name = args.shift();
          var deleteModal;

          deleteModal = openModal({
            modal: {
              dismissable: true,
              title: 'Confirm Delete',
              html: '<p>Are you sure you want to delete <strong>' + name + '</strong> ?</p>',
              buttons: [{
                classes: 'btn-danger',
                text: 'Delete',
                click(e) {
                  deleteModal.close(e);
                }
              }, {
                classes: 'btn-default',
                text: 'Cancel',
                click(e) {
                  deleteModal.dismiss(e);
                }
              }]
            }
          }, 'modal-danger');

          deleteModal.result.then(function(event) {
            del.apply(event, args);
          });
        };
      }
    }
  };
}

export default angular.module('workspaceApp')
  .factory('Modal', Modal)
  .name;

@Azayzel
Copy link
Contributor

Azayzel commented Sep 23, 2016

Your specific issue seems to be case. In your app.js you're importing with lowercase 'm' but in your controller your using it as 'M'. Try fixing it to a capital 'M' when importing and in your injection.

With that being said; i am also having trouble with this Modal. When i call $uibModal directly from my controller it works the way a Modal should. But not via this service.

@Azayzel
Copy link
Contributor

Azayzel commented Sep 23, 2016

Ive created a PR that fixes this issue. #2256

The problem lies at the export of the factory. Change

export default angular.module('workspaceApp')
  .factory('Modal', Modal)
  .name;

to

export default angular.module('workspaceApp.Modal',[])
  .factory('Modal', Modal)
  .name;

@Awk34 Awk34 closed this as completed in 68b7b69 Sep 26, 2016
@hopeworkscamden
Copy link
Author

Thanks @Azayzel ! I really appreciate it! Got my first modal to pop up today using the Modal service. Next stop is injecting the controller scope i'm calling the modal from into the modal itself.

@marwenlandoulsi
Copy link

marwenlandoulsi commented Dec 29, 2016

Please i need help. i have got this bug :

vendor.bundle.js:14047 Error: [$injector:strictdi] Modal is not using explicit annotation and cannot be invoked in strict mode
http://errors.angularjs.org/1.5.8/$injector/strictdi?p0=Modal
at http://localhost:8086/vendor.bundle.js:195:13
at Function.annotate [as $$annotate] (http://localhost:8086/vendor.bundle.js:4079:18)
at injectionArgs (http://localhost:8086/vendor.bundle.js:4806:37)
at Object.invoke (http://localhost:8086/vendor.bundle.js:4837:19)
at Object.enforcedReturnValue [as $get] (http://localhost:8086/vendor.bundle.js:4684:38)
at Object.invoke (http://localhost:8086/vendor.bundle.js:4845:20)
at http://localhost:8086/vendor.bundle.js:4644:38
at getService (http://localhost:8086/vendor.bundle.js:4791:40)
at injectionArgs (http://localhost:8086/vendor.bundle.js:4815:59)
at Object.instantiate (http://localhost:8086/vendor.bundle.js:4857:19)
at $controller (http://localhost:8086/vendor.bundle.js:10496:29)
at Object. (http://localhost:8086/vendor.bundle.js:38077:29)
at http://localhost:8086/vendor.bundle.js:1374:19
at invokeLinkFn (http://localhost:8086/vendor.bundle.js:10061:10)
at nodeLinkFn (http://localhost:8086/vendor.bundle.js:9462:12)
at compositeLinkFn (http://localhost:8086/vendor.bundle.js:8747:14)
at publicLinkFn (http://localhost:8086/vendor.bundle.js:8627:31)
at lazyCompilation (http://localhost:8086/vendor.bundle.js:8971:26)
at updateView (http://localhost:8086/vendor.bundle.js:38005:24)
at http://localhost:8086/vendor.bundle.js:37954:12
at Scope.$broadcast (http://localhost:8086/vendor.bundle.js:18132:29)
at http://localhost:8086/vendor.bundle.js:37335:23
at processQueue (http://localhost:8086/vendor.bundle.js:16510:29)
at http://localhost:8086/vendor.bundle.js:16526:28
at Scope.$eval (http://localhost:8086/vendor.bundle.js:17809:29)
at Scope.$digest (http://localhost:8086/vendor.bundle.js:17622:32)
at Scope.$apply (http://localhost:8086/vendor.bundle.js:17917:25)
at bootstrapApply (http://localhost:8086/vendor.bundle.js:1888:16)
at Object.invoke (http://localhost:8086/vendor.bundle.js:4845:20)
at doBootstrap (http://localhost:8086/vendor.bundle.js:1886:15)
at Object.bootstrap (http://localhost:8086/vendor.bundle.js:1906:13)
at http://localhost:8086/app.bundle.js:100:22
at HTMLDocument.trigger (http://localhost:8086/vendor.bundle.js:3334:8)
at defaultHandlerWrapper (http://localhost:8086/vendor.bundle.js:3624:12)
at HTMLDocument.eventHandler (http://localhost:8086/vendor.bundle.js:3612:10)

Any solution ??

@zaphinath
Copy link

I'm seeing the same issue - angular.js:14525 Error: [$injector:strictdi] Modal is not using explicit annotation and cannot be invoked in strict mode.

Any solution?

@thedewpoint
Copy link

thedewpoint commented Apr 24, 2017 via email

@zaphinath
Copy link

#2203 Fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants