0

I built web app with angular1 and webpack2.

I want to make modal popup with own state so I used ui.router and

ui.bootstrap.

But the problem is, onEnter method doesn't work.

below is my app.js,

and I brought codes about modal at here :

Open Modal and change URL without change the view in AngularJS

import angular from 'angular';
import 'angular-ui-router';
import 'angular-ui-bootstrap';
import 'angular-resource';

// controllers
import homeController from './pages/home/home-controller';
import playerController from './pages/player/player-controller';
import toolbarController from './components/toolbar-controller';

angular.module('907dg', [
  'ui.router',
  'ui.bootstrap'
])

.config(($stateProvider, $locationProvider) => {
  $stateProvider
  .state('home', {
    url: '/',
    template: require('./pages/home/home.html'),
    controller: 'HomeController'
  })


  // modal codes
  .state('player', {
    url: '/player/:playerName',
    onEnter: function($stateParams, $state, $modal) {
      console.log('here is player modal');
      $modal.open({
        template: '<div><h1>PLAYER MODAL POPUP</h1></div>',
        resolve: {},
        controller: function($scope, $state) {
          $scope.ok = function () {
            $scope.$close();
          };
          $scope.dismiss = function () {
            $scope.$dismiss();
          };
        }
      }).result.then(function (result) {
         // $scope.$close
      }, function (result) {
         // $scope.$dismiss
      }).finally(function () {
        // finally
        return $state.transitionTo('home');
      });
    }
  });


  $locationProvider.html5Mode({
    enabled: true,
    requireBase: false
  });
})

.controller('MasterController', ($scope) => {
  $scope.greeting = 'HERE IS INDEX';
})

.filter('trustAsResourceUrl', ['$sce', function($sce) {
  return function(val) {
      return $sce.trustAsResourceUrl(val);
  };
}]);

playerController();
homeController();
toolbarController();

and the controller that calls modal.

$scope.show = function (pName) {
  $state.go('player', { playerName: pName });
};
hagfish1210
  • 115
  • 1
  • 1
  • 7
  • are you getting any console error – Vasantha Raj May 30 '17 at 05:41
  • i think u build a wrong code for this line : [templateUrl: '

    PLAYER MODAL POPUP

    ',.] when you are using template directly you can use template property, ex : template: '

    PLAYER MODAL POPUP

    ',
    – Vasantha Raj May 30 '17 at 05:46
  • oh thank you for comment. that was little mistake. fixed it now, but problem is still remain :( any advice? – hagfish1210 May 30 '17 at 06:10
  • Check your browser console, if get any error update me. i can not understand your issue – Vasantha Raj May 30 '17 at 06:20
  • kindly check this function: $scope.show = function (pName) { console.log("if you get pName here, your code working fine"); $state.go('player', { playerName: pName }); }; – Vasantha Raj May 30 '17 at 06:38
  • I just added console.log(pName); to show function, and got pName well in browser console. With no errors. So weird! there is no error but onEnter function ignore me completely. – hagfish1210 May 30 '17 at 07:21
  • create a plunker and post it – svarog May 30 '17 at 09:04

0 Answers0