1

I'm using Yeoman + AngularJS + Ui Router. When I`m used ng-router its possible open mobile browser (local-ip):9000 and use app, but with Ui Router I can not do the same. Should I setup something?

For eg: Run grunt server in computer. Open my browser in mobile and access my local ip:port.

Bit of code:

app.js

.config(['$locationProvider', '$urlRouterProvider', '$httpProvider',
    function($locationProvider, $urlRouterProvider, $httpProvider) {
        $locationProvider.html5Mode(true).hashPrefix('!');

        $urlRouterProvider.otherwise('/404');

        $httpProvider.interceptors.push('AuthInterceptorService');
    }
.run(['$rootScope', 'AuthenticationService', '$state',
    function($rootScope, AuthenticationService, $state) {
        var routesThatRequireAuth = ['/dashboard'];

        $rootScope.$on('$stateChangeStart',
            function(event, toState) {
                if (_.contains(routesThatRequireAuth, toState.url) && !AuthenticationService.isLoggedIn()) {
                    event.preventDefault();
                    $state.transitionTo('login');
                } else if (toState.url === '/' && AuthenticationService.isLoggedIn()) {
                    event.preventDefault();
                    $state.transitionTo('dashboard');
                }
            });
    }
]);

login.js

'use strict';

angular.module('App').config(['$stateProvider',
    function($stateProvider) {
        $stateProvider
            .state('login', {
                url: '/',
                views: {
                    '': {
                        templateUrl: 'views/login/login.html',
                        controller: 'LoginCtrl'                        
                    },
                    'header@login': {
                        templateUrl: 'views/layouts/anonymous/header.html'
                    },
                    'body@login': {
                        templateUrl: 'views/login/body.html'
                    }
                }
            });
    }
]);
3
  • can you describe how you do it with angular router? it's not clear what do you want to do without looking at the code Commented Oct 13, 2014 at 14:30
  • Are you sure the problem is not related to AuthenticationService? Couldn't it be a problem in accessing a route that is hardcoded in the service? Commented Oct 26, 2014 at 12:19
  • Pretty sure! I'm not used to hardcode =D Commented Oct 26, 2014 at 18:21

2 Answers 2

2
+25

If you need to debug Angular application on mobile device you can checkout this https://developer.chrome.com/devtools/docs/remote-debugging

Sign up to request clarification or add additional context in comments.

1 Comment

Hey this helps a lot, but isn't what I looking for. I almost sure thats a way to use device like ng-route, using just wifi connection.
0

Your question is: How can I connect to my Angular/Node test server from my mobile device.

First off, your server and other test devices you will be testing with will need to be connected to the same network. This means that if you're trying to test with your cellphone through 3G it will not work.

Normally you just need to connect via WiFi to the same router your PC is connected to.

Then you need to figure out what IP your server is using. Whenever you're testing locally your address bar shows "localhost" or "127.0.0.1" these two addresses are refered to as loopback addresses and they won't work if you're putting that address in your mobile device.

To obtain the actual IP address, if you're on windows open a command line and type ipconfig from the computer you are developing from and you will see your IP address.

Now with that information you can test by running your server and opening a browser in your mobile device. In the address bar type http://192.168.1.5:9000 (replacing 192.168.1.5 with your actual IP address) and press go.

You should now be able to view your site from your mobile. Keep in mind that a multitude of things can go wrong. You could have a firewall on, you router may block your server with a NAT, or your IP could be dynamically changed.

Pro tip: Figure out how to get a static IP and either use a domain name or a DynDNS service like https://zzzz.io/ for quicker/easier testing.

1 Comment

As I said, when I'm using ng-route everything works, but when I changed to ui-route has a problem. My problem isn't in network configuration. By the way your tip can help others =D, thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.