angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.12k stars 1.24k forks source link

use of Modal.service #2434

Closed marwenlandoulsi closed 7 years ago

marwenlandoulsi commented 7 years ago
Item Version
generator-angular-fullstack 4.1.0
Node 6.9.1
npm 3.10.8
Operating System Windows 10
Item Answer
Transpiler Babel
Markup HTML
CSS CSS
Router ui-router
Client Tests Jasmine
DB MongoDB
Auth Y

I need help : when i use the modal.service.js, i got this bug. any solution please.

this is my Admin.controller.js :

'use strict';

export default class AdminController {
  users: Object[];
  $http;
  /*@ngInject*/
  Modal;

  constructor(User, $http, Modal) {
    // Use the User $resource to fetch all users
    this.users = User.query();
    this.$http = $http;
    this.Modal = Modal;
  }

  delete(user) {

    this.Modal.confirm.delete(user => {
      user.$remove();
      this.users.splice(this.users.indexOf(user), 1);
    });
  }
}

and the app. js :

import Modal from '../components/modal/modal.service';

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

    $rootScope.$on('$stateChangeStart', function (event, next) {
      Auth.isLoggedIn(function (loggedIn) {
        if (next.authenticate && !loggedIn) {
          $location.path('/login');
        }
      });
    });
  });

angular.element(document)
  .ready(() => {
    angular.bootstrap(document, ['safetyWayApp'], {
      strictDi: true
    });
  });

finnaly this is the bug :

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)

Awk34 commented 7 years ago

In client/components/modal/modal.service.js, after this line:

export function Modal($rootScope, $uibModal) {

add this:

'ngInject';

It might be easier to use the ui-bootstrap modal directly, though.

marwenlandoulsi commented 7 years ago

same problem :(

Awk34 commented 7 years ago

Please fix the code formatting in your OP so I can read it

marwenlandoulsi commented 7 years ago

done i fix it

Awk34 commented 7 years ago

The placement of your /*@ngInject*/ directive is incorrect. See https://github.com/huston007/ng-annotate-loader & https://github.com/olov/ng-annotate#library-api

marwenlandoulsi commented 7 years ago

thinks it's work :)