1

I can't get UI-Router to work, which is really annoying because I'm building a site off of another site I built where it was working fine. Currently, ui-view is not displaying anything, and ui-sref links are not clickable or redirecting. I'm not getting any errors either. My code is below. Any help would be much appreciated!

JS: app.js

var app = angular
    .module("RssTransfers", ["ui.router"])
    .config(MainRouter);

    function MainRouter($stateProvider, $urlRouterProvider) {
        $urlRouterProvider.otherwise('/');

        $stateProvider
            .state('transfers', {
                url: '/',
                templateUrl: 'transfers.html',
            })

            .state('about', {
                url: '/about',
                templateUrl: 'about.html'
            })

            .state('upload', {
                url: '/upload',
                templateUrl: 'upload.html'
            })
    };

HTML: index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <title>RSS Transfers</title>

  <link rel="stylesheet" type="text/css" href="./css/materialize.css" />
  <link rel="stylesheet" type="text/css" href="./css/style.css" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js"></script>
  <script src="./js/ng-file-upload-shim.min.js"></script> <!-- for no html5 browsers support -->
  <script src="./js/ng-file-upload.min.js"></script>
  <script src="./js/app.js"></script>
  <script src="./js/transferController.js"></script>
  <script src="./js/uploadController.js"></script>
  <script src="./js/materialize.js"></script>
</head>
<body ng-app="RssTransfers">

    <div ng-include="'navbar.html'"></div>

    <div class="wrapper" ui-view></div>


</body>
</html>

dummy text to display: transfers.html

<div ng-controller="TransferController as transfer">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi, est, cum. Dicta, eius obcaecati quia culpa ipsam quibusdam tempore adipisci molestias optio, nam corporis, veritatis voluptatem incidunt cumque a sequi?</p>
</div>

As requested, here's the code for the controller:

TransferController.js

angular.module('RssTransfers')
    .controller('TransferController', TransfersController);

TransfersController.$inject = ['$http'];

function TransfersController($http){
    var self = this;
    self.all = [];
    self.addTransfer = addTransfer;
    self.newTransfer = {};
    self.getTransfer = getTransfer;

    getTransfers();
    function getTransfers(){
        $http
            .get('http://localhost:3000/transfers/')
            .then(function(response){
                self.all = response.data.transfers;
        });
    }

  function addCriminal() {
      $http
          .post('http://localhost:3000/transfer', self.newTransfer)
          .then(function(response){
              getTransfers();
    });
    self.newTransfer = {};
  }

}
3
  • Did you try to add a breakpoint in your MainRouter function ? Commented Dec 9, 2015 at 13:47
  • 1
    A plunkr would help... Commented Dec 9, 2015 at 13:50
  • I did throw in a breakpoint within app.js, but it never hit the debugger. I imagine my error has something to do with instantiating the module, but I just can't see it Commented Dec 9, 2015 at 13:53

3 Answers 3

1

Solved, although I'm not sure why. I deleted my frontend files and started from scratch, and it works fine. I suspect there may be an issue with ui-router and ng-file-upload conflicting, but I'll tackle that issue when I get there.

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

Comments

0

I've taken your code and created a plunkr here. Note - that it doesn't contain the controller just yet.

angular.module('RssTransfers',['ui.router']);

(function() {
  'use strict';

  angular
    .module('RssTransfers')
    .config(routing);

  routing.$inject = ['$stateProvider', '$urlMatcherFactoryProvider', '$urlRouterProvider'];

  function routing( $stateProvider, $urlMatcherFactoryProvider, $urlRouterProvider ){

    $urlMatcherFactoryProvider.strictMode(false);

    // For any unmatched url, redirect to /root
    $urlRouterProvider.otherwise("/transfers");

     $stateProvider
        .state('transfers', {
            url: '/transfers',
            templateUrl: 'transfers.html',
        })
        .state('about', {
            url: '/about',
            templateUrl: 'about.html'
        })
        .state('upload', {
            url: '/upload',
            templateUrl: 'upload.html'
        });
  }
})();

though I'm still unsure why yours doesn't work...

3 Comments

Thanks, you beat me to it, as I was just in Plunker now. Yeah, I'm staring at it and nothing.
I'd suggest removing every file that isn't necessary for the ui-router to render as it may be one of those that are getting in the way - or it just means that your path to the templates is wrong
Thanks, I'll give that a go. Templates are in the same directory, so that shouldn't be affecting it, but I'm happy to remove bit by bit to see where the issue is!
0

originally, i only had added the the provideRouters(routes)to the app.component.ts file, but after adding it to the main.ts file when bootstrap builds, the ui rendered fine

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.