2016-06-14 159 views
0

我是angularJs中的一名新程序员。我正在实施一个简单的CRUD应用程序,显示客户端列表。 从客户端列表中,我有一个“添加客户端”按钮,允许移动到AddClient视图。 点击保存按钮addClientView后,我想发送请求保存客户端ans然后,返回客户端列​​表AngularJs如何从一个控制器切换到另一个控制器

这里是我的app.js处理客户端保存的函数:

$scope.addClient = function(isValid) { 
    if (!isValid) { 
     $scope.displayValidationError = true; 
     return; 
    } 

    var url = "/myApp/clients/add"; 

    var config = { 
     headers : { 
      'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8' 
     } 
    }; 

    $http.post(url, $.param($scope.client), config).success(
      function(data) { 
       var urlWhereToBack = "/myApp/clients/list"; 
       //here code to launch this url and switch to the list of client 
       ........ 
       ........ 
      }).error(function(data, status, headers, config) { 
     $scope.handleRequestError(status); 
    }); 
}; 

所以,保存后的客户端,我要启动的URL“/对myApp /客户/列表”按钮返回到客户端的YHE名单

我怎么能做到这一点吗?

+0

如果不使用ui-router,可以使用'$ state.go('some.state')' – reptilicus

+1

或'$ location.path(view)',但我建议你应该。 – reptilicus

回答

0

您不想在Angular中按URL浏览“views”。

看看ui-router并使用$ stateS。

相关问题