Passing variable to Modal window in Angular with Jade and CoffeeScript

时间:2015-10-29 15:55:17

标签: angularjs coffeescript pug

I am trying to pass a value from a page to a pop-up modal window but the browser gives me an undefined value. Following is my page controller function for the modal window

$scope.showUserDetails =  (user) ->
modalInstance = $modal.open
  templateUrl: "/partials/user_details.html"
  controller: "UserDetailCtrl"
  keyboard: true
  resolve:
      selectedUser: ->
        user

modalInstance.result.then (args) ->
    updateFilter()

and the following is my modal window controller

.controller('UserDetailCtrl', [
'$scope'
'$modalInstance'
'selectedUser'
($scope,$location,$http,$modalInstance,selectedUser) ->
    console.log(selectedUser);
    $scope.user = selectedUser;
])

But the variable selectedUser is always undefined. I even tried passing a string instead of the variable 'user' in the main controller but I still get an undefined value.

1 个答案:

答案 0 :(得分:1)

根据您所做的评论,问题是您列出的依赖项。在您的控制器函数中,您引用了$location$http,但未将它们列在字符串名称数组中。要解决此问题,您需要从控制器中删除它们(如果您不使用它们),或者在字符串列表中正确指定它们。

从控制器中删除

.controller('UserDetailCtrl', [
  '$scope'
  '$modalInstance'
  'selectedUser'
  ($scope,$modalInstance,selectedUser) ->
    console.log(selectedUser);
    $scope.user = selectedUser;
])

或添加到字符串列表

.controller('UserDetailCtrl', [
  '$scope'
  '$location',
  '$http',
  '$modalInstance'
  'selectedUser'
  ($scope,$location,$http,$modalInstance,selectedUser) ->
    console.log(selectedUser);
    $scope.user = selectedUser;
])