【问题标题】:Angularjs routing with dataAngularjs路由与数据
【发布时间】:2015-06-03 05:44:56
【问题描述】:

当我单击部门列表中的查看按钮时,视图模板上未显示数据。我没有使用任何服务。 请帮帮我…………

我的源代码如下......

我的 Angularjs 控制器:

    .when('/Edit/:Id', {
        templateUrl: baseSiteUrlPath + 'Templates/Hrm_dept/Edit.html',
        controller: 'DeptCtrl'
    })

DeptApp.controller('DeptCtrl', function ($scope, $routeParams, $location, $route) {

$scope.Dept = {};
$scope.Dept1 = {};
$scope.DeptList = [];
$scope.DeptList1 = [];
$scope.ishide = true;   

$scope.DeptView = function (Dept) {
    console.log(Dept);
    **$scope.Dept1 = angular.copy(Dept);**
    var id = 1;
    **var earl = '/Edit/' + id;**
    $location.path(earl);
    $scope.$apply();
};

});

这是我的列表模板: ng-click="DeptView(Dept)"

这是我的视图模板: 部门名称:ng-model="Dept1.DEPT_NAME"

【问题讨论】:

  • 而不是 jQuery.ajax 试试 $http
  • 您是否在控制台中遇到任何错误? $scope.$apply() 可能会抛出错误
  • 是的。错误:[$rootScope:inprog] $apply 已经在进行中,但如果我评论 // $scope.$apply() 不显示错误但不显示任何数据以查看模板。
  • 如何通过 angularjs 路由传递对象 .when('/Edit/:Id', { templateUrl: baseSiteUrlPath + 'Templates/Hrm_dept/Edit.html', controller: 'DeptCtrl' })跨度>

标签: jquery angularjs


【解决方案1】:

尝试以下操作(不要忘记在控制器中声明 $http

$http.get('/HRM_DEPT/GetAllDepartment').
      success(function(data, status, headers, config) {
        $scope.DeptList = data;
     // this callback will be called asynchronously
        // when the response is available
      }).
      error(function(data, status, headers, config) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
      });

【讨论】:

  • 列表正在显示,但是当我单击部门列表中的查看按钮并触发此功能时,部门值未显示以查看模板.. $scope.DeptView = function (Dept) { console.log(部门); $scope.Dept1 = angular.copy(Dept);变量 ID = 1; var 伯爵 = '/编辑/' + id; $location.path(伯爵); $scope.$apply(); };
猜你喜欢
  • 2017-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-30
  • 2015-07-06
  • 1970-01-01
  • 1970-01-01
  • 2014-04-12
相关资源
最近更新 更多