2015-02-11 57 views
-1

我在Plunkr中有以下代碼。 http://plnkr.co/edit/8sBafktFzFa8fCLLJgMF從控制器調用數據到HTML視圖AngularJS

這是我的JS文件

angular.module('ui.bootstrap.demo', ['ui.bootstrap']); 
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function ($scope, $modal, $log) { 



    $scope.open = function (size) { 

    var modalInstance = $modal.open({ 
     templateUrl: 'myModalContent.html', 
     controller: 'ModalDemoCtrl', 
     size: size 
    }); 

    var applicantID = 12; 
    }; 


    $scope.submit_info = function (size) { 

    var modalInstance = $modal.open({ 
     templateUrl: 'myModalContent1.html', 
     controller: 'ModalDemoCtrl', 
     size: size 
    }); 
    }; 
}); 

,這是我的html頁面

<!doctype html> 
<html ng-app="ui.bootstrap.demo"> 
    <head> 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script> 
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.0.js"></script> 
    <script src="example.js"></script> 
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> 
    </head> 
    <body> 

<div ng-controller="ModalDemoCtrl"> 
    <script type="text/ng-template" id="myModalContent.html"> 

      <h3>I'm a modal!</h3> 

      <button class="btn btn-default" ng-click="submit_info('lg')">Submit</button> 

    </script> 
    <script type="text/ng-template" id="myModalContent1.html"> 

      <h3>CaseID: </h3> 
      {{ applicantID }} 

    </script> 

    <button class="btn btn-default" ng-click="open()">Set caseID</button> 

</div> 
    </body> 
</html> 

我希望能夠在點擊按鈕「SETID」,並在點擊按鈕分配applicantID「提交「,它顯示已通過的'12'的申請人ID值。但它一直傳遞一個空的數據。

+0

哪裏是參考角,其中NG-應用程序? – Chandermani 2015-02-11 04:02:38

回答

0

您需要的NG-應用程序,並刪除此$模式,我定你的提琴:

http://jsfiddle.net/u0nhwa4w/2/

angular.module('loanstreetIpadAppApp',[]) 
.controller('Mortgage_LoanCtrl', function ($location, $scope, $http, $sce) { 
    var applicantID; 
    $scope.submit_info = function() { 
      applicantID = 12; 
      getusercaseID(applicantID); 
    }; 

    var getusercaseID = function(id) { 
    $scope.page_data = id; 
    console.log("yes come on "); 
    console.log($scope.page_data); 
    }; 
}); 
+0

$ modal不是Angular核心的一部分,所以如果你想使用它,你需要爲它添加一個庫。 – 2015-02-11 04:16:40

+0

哦,你還需要[]在angular.module('loanstreetIpadAppApp',[]) – 2015-02-11 04:19:53

+0

我只從我的控制器添加了代碼,因此我沒有附加ngApp部分我的壞。另外$ modal在我的代碼中有bcos,我稱之爲$模態,而applicantID是我想要傳遞給模態的數據。與您實現的唯一區別是觸發響應的按鈕。在我的代碼中,我提交按鈕tht觸發它,但它不起作用,因此我爲什麼在d fiddle文件中使它成爲ng-init。我的代碼非常長,因爲它有http posts nd all。我沒有看到你的代碼和我的很多不同。也許我會用模態部分更新它以獲得更多的說明。感謝RTPMatt – 2015-02-11 05:39:37

相關問題