angularjs路由没有链接

时间:2016-03-11 14:56:39

标签: html angularjs angularjs-routing

我有两个问题 首先,我的test.html没有"看到"来自他的控制器的产品阵列 我不知道为什么,我已经将控制器与routing.config.js中的html连接起来。

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);
  }
});

我想要的第二件事是test.html将被激活而不会点击链接。
如果加载了主页,则也应该加载test.html 最后我想删除<ul>,但结果应该相同。 (foo和下拉列表)。

我已经找到了PLUNK,你可以看到问题。

我唯一的解决方案是将routing.config.js中的test.controller.js和start.html中的test.html集成在一起。
但我希望避免这种情况,因为它会使代码更加混乱。

我也查看了ui-router文档,但它对我没用。

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

我希望有人有个主意......谢谢! =)

1 个答案:

答案 0 :(得分:1)

我会接受@ charlietfl的建议并阅读嵌套视图。除此之外,你的plunkr中有一些错误:

  1. 忘记在test-controller.js
  2. 中加载index.html
  3. 忘记将product-selection模块注入myapp(因此可以解析相应的控制器)
  4. 忘记将ngModel添加到test.html中的select元素,以便数据绑定按预期工作
  5. 在这里,plunkr更新了正确填充的选择控件。