(Angular) Simple nested views not working

91 Views Asked by At

I'm studying Angular, and I'm stuck with ui-router.
Here is the code. I'm using PUG & Livescript, I doubt that I'm having issue because of these two.

My codes are similar to some answers here in stackoverflow, but I can't make it to work. create.pug is not showing.

main.pug is a child of index.pug
create.pug is a child of main.pug

create.pug -> main.pug -> index.pug

versions:

angular -> 1.6.3
angular-ui-router -> 0.4.2

index.pug

html(ng-app="app.main")
  head ...
  body
    div(ui-view)

main.pug

md-subheader
  h1 To Do

md-divider
section(ui-view)

create.pug

md-input-container
  label Title
  input(type="test" ng-model="app.new_task" ng-keypress="createTask($event)")

main.ls

MainController = ($scope) !->

angular
  .module 'app.main'
  .controller 'MainController', MainController

create.ls

TaskCreateController = ($scope) !->
  app = @

  app.taskList = []

  $scope.createTask = ($event) !->
    if $event.keyCode !== 13 || !app.new_task
      return

  app.taskList.push app.new_task
  app.new_task = ''

  angular
    .module 'app.main'
    .controller 'TaskCreateController', TaskCreateController

router.ls

routeHelper = ($locationProvider, $stateProvider, $urlRouterProvider) !->
this.$get = ($state) ->
  'configureStates': (states) !->
      Object
        .entries states
        .forEach ([name, config]) !->
          $stateProvider.state name, config

$locationProvider.html5Mode false
$urlRouterProvider.otherwise '/'

angular
  .module 'app.main'
  .provider 'routeHelper', routeHelper

routes.ls

setupRoutes = (routeHelper) !->
  routeHelper.configureStates do
    'home':
      'url': '/'
      'templateUrl': 'modules/main/main.html'
      'controller': 'MainController'
      'controllerAs': 'app'

    'home.create':
      'url': '/create'
      'templateUrl': 'modules/task/create/create.html'
      'controller': 'TaskCreateController'
      'controllerAs': 'app'

angular
  .module 'app.main'
  .run setupRoutes
1

There are 1 best solutions below

1
Ehvince On

mmh I'd try to add an indentation level here:

head(ng-app="app.main") ...
body
  div(ui-view)

to

head(ng-app="app.main") ...
  body
    div(ui-view)

or rather

html(ng-app="app.main")
  head
  body