将数据从控制器调用到HTML视图AngularJS

Calling Data from Controller to HTML view AngularJS

本文关键字:HTML 视图 AngularJS 调用 数据 控制器      更新时间:2023-09-26

我在Plunkr中有以下代码。http://plnkr.co/edit/8sBafktFzFa8fCLLJgMF

这是我的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"时分配应用程序ID,并在点击按钮"submit"时显示传递的应用程序ID值"12"。但它一直在传递一个空数据。

你需要ng应用程序,为了删除这个$modal,我修复了你的fiddle:

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);
   };
});