theoretisch
theoretisch

Reputation: 1728

angularjs routing without links

I have two problems.
First my test.html doesn't "see" the products array from his controller.
I don't know why, I have connected the controller with the html in the routing.config.js.

var myapp = angular.module('myapp', ["ui.router", "ngAnimate"]);

myapp.config(function($stateProvider, $urlRouterProvider){    
  $stateProvider
      .state("foo", {
          url: "/foo",
          templateUrl:'start.html'
      })
      .state("test", {
          url: "/test",
          templateUrl: 'test.html',
          controller:'product-controller',
          parent:'foo'
      })

  $urlRouterProvider.otherwise("/foo");
})

myapp.controller('navCtrl', function($scope, $state){

  $scope.navigateTo = function(target){
     $state.go(target);
  }
});

the second thing I want is that the test.html will be activated without the click on the link.
If the mainpage is loaded, the test.html should be loaded too.
At the end I want to delete the <ul> but the result should be the same. (the foo and the dropdown).

I have made a PLUNK where you can see the problem.

The only solution I had, is to integrate the test.controller.js in the routing.config.js and the test.html in the start.html.
But i hope to avoid this because it makes the code more confusing.

I also looked at the ui-router docs but it doesn't work for me.

    .state("foo.test", {
          url: "/test",
          templateUrl: 'test.html',
          controller:'product-controller',
          parent:'foo'
      })

I hope someone has an idea... thank you! =)

Upvotes: 1

Views: 77

Answers (1)

chris
chris

Reputation: 1817

I would take @charlietfl's advice and read up on nested views. Other than that, you had a few errors in your plunkr:

  1. Forgot to load test-controller.js in index.html
  2. Forgot to inject the product-selection module to myapp (so it can resolve the respective controller)
  3. Forgot to add the ngModel to the select element in test.html for data binding to work as expected

Here's your plunkr updated with the select control populated properly.

Upvotes: 1

Related Questions