模态不读取$ scope输入

时间:2014-02-04 17:33:22

标签: javascript angularjs

我的申请表中有以下内容:

的index.html

<script type="text/ng-template" id="company_setup.html">
    <div class="modal-header">
        <h3 class="newWidget">Please enter your company id</h3>
    </div>
    <div class="modal-body" ng-controller="CacheListController">
        <form class="form-horizontal">
            <div class="control-group">
                <label class="control-label" for="inputType">Company Id</label>

                <div class="controls">
                    <input type="text" id="inputType" ng-model="company_id" placeholder="Company Id">
                </div>
            </div>
        </form>
    </div>
    <div class="modal-footer">
        <button class="btn btn-success" ng-click="choice('tryToSetCompany')">OK</button>
    </div>
</script>

问题只是当你在输入框中输入company_id时,点击确认来自Restangular的响应为:GET https://www.bookingbug.com/api/v1/company/undefined 403 (Forbidden)我对此的理解是$scope.company_id未被读取。这只是因为在我的Dialogcontroller中设置了新的$scope

更新:

$scope.tryToSetCompany = function() {
  var response;
  response = Restangular.oneUrl('bookingbug', 'https://www.somesite.com/api/v1/company/' + $scope.company_id).get();
  if (response.status !== 200) {
     $scope.company = {
      comapny_id: null
    };
  }
};

2 个答案:

答案 0 :(得分:0)

bbPlnkr.controller('DialogController', function($scope, Snippet, $rootScope, $modalInstance, Restangular) 
{ $scope.cancel = function() { return $modalInstance.dismiss("cancel"); };
 return 
$scope.choice = function(action) { return $modalInstance.close(action); };
 }
)

$ scope.cancel和$ scope.choice之间有额外的回报,很可能是$ scope.choice未定义

答案 1 :(得分:0)

试试这个

$scope.company= {
    company_id: null
}

并在HTML

ng-model="company.company_id"