Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何预设ui.router$stateParam_Javascript_Angularjs_Routing - Fatal编程技术网

Javascript 如何预设ui.router$stateParam

Javascript 如何预设ui.router$stateParam,javascript,angularjs,routing,Javascript,Angularjs,Routing,我有一个带有两个或多个视图和链接的仪表板来加载这些视图,在视图1上,您可以选择一个客户,一旦客户设置好要转到视图2的链接,则应使用customerId来显示客户的相关内容 使用$state.go添加链接并设置$stateParams var可以正常工作,但是$sate链接位于父模板和控制器中 通过$state链接将customerId值(一旦选择)分配给state的最佳方式是什么,即用户选择客户,然后选择link to view 2查看客户的联系人 我创建了一个plunker来演示 索引HTML

我有一个带有两个或多个视图和链接的仪表板来加载这些视图,在视图1上,您可以选择一个客户,一旦客户设置好要转到视图2的链接,则应使用customerId来显示客户的相关内容

使用$state.go添加链接并设置$stateParams var可以正常工作,但是$sate链接位于父模板和控制器中

通过$state链接将customerId值(一旦选择)分配给state的最佳方式是什么,即用户选择客户,然后选择link to view 2查看客户的联系人

我创建了一个plunker来演示

索引HTML 仪表板

-------这是仪表板控制器----------

-------这是ViewOneController----------


它正在工作情况如何?如何获得链接“Customer Contacts(View 2)”以将customerId var传递到View 2?或者将var分配给状态链接。我正在处理,请稍等DashboardController中的链接。顺便说一句,您可以添加一些验证和内容,但这是基本的。。。它也不像链接,但你可以添加一些css。。
<ul>
  <li><a ui-sref="view1">Customer Search/Select (View 1)</a></li>
  //here is the change
  <li><a ng-click="go()">Customer Contacts (View 2)</a></li>

</ul>
.

service("selectedCustomer",function(){
  var selected={};
  return {

    select:function(customerId){
      selected.customerId=customerId;
    },

    get:function(){
      return selected;
    }
  }});
    var DashboardController = function($scope,$state,selectedCustomer){
    $scope.go = function() {
      console.log(selectedCustomer.get().customerId);
        $state.go('view2', {customerId: selectedCustomer.get().customerId});
    };
};
var ViewOneController = function($scope, $state, $stateParams,selectedCustomer){
  $scope.customers = [
    {"id": 21, "name": "Customer #21"},
    {"id": 22, "name": "Customer #22"},
    {"id": 23, "name": "Customer #23"},
    {"id": 24, "name": "Customer #24"},
    {"id": 25, "name": "Customer #25"}
    ];

    $scope.update=function(){
      selectedCustomer.select($scope.customerId);
    }


};