ng-click功能不起作用

时间:2017-06-19 02:55:49

标签: javascript jquery angularjs

var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(function($routeProvider) {
  $routeProvider.when('/', {
    template: '',
    controller: 'DefaultController as dc'
  }).when('/rent', {
    templateUrl: 'views/partials/rent.html',
    controller: 'rentController as rc'
  }).when('/buy', {
    templateUrl: 'views/partials/buy.html',
    controller: 'buyController as bc'
  });

}); //end config

myApp.controller('DefaultController', DefaultController);
myApp.controller("rentController", rentController);
myApp.controller("buyController", buyController);

function DefaultController() {
  console.log('inside of DefaultController');
  var vm = this;
  vm.checkPost = function() {
    console.log('checkpost clicked');
  };

} //end controller

function rentController(RealStateService) {
  console.log('inside of rent controller');
  var vm = this;
  vm.rentArray = [];
  vm.info = false;


  vm.getProperties = function() {
    console.log('port');
    RealStateService.serverPractice().then(function(res) {

      RealStateService.data.forEach(function(data) {
        if (data.rent) {
          vm.rentArray.push(data);
        }
      }); //end for each

    }); //end then
  }; //end getProperties

  vm.showInfo = function(index) {
    vm.info = true;
    console.log('in get Info');
    vm.info = vm.rentArray[index];
    console.log(vm.info);
  }; //end get info
}

function buyController(RealStateService) {
  console.log('inside of buy controller');
  var vm = this;
  vm.rentArray = [];
  vm.info = false;


  vm.getProperties = function() {
    RealStateService.serverPractice().then(function(res) {

      RealStateService.data.forEach(function(data) {
        if (data.cost) {
          vm.rentArray.push(data);
        }
      }); //end for each

    }); //end then
  }; //end getProperties

  vm.showInfo = function(index) {
    vm.info = true;
    console.log('in get Info');
    vm.info = vm.rentArray[index];
    console.log(vm.info);
  }; //end get info

}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title> Weekend Challenge #5</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" href="styles/style.css">
  <script src="vendors/angular.min.js" charset="utf-8"></script>
  <script src="vendors/angular-route.min.js" charset="utf-8"></script>
  <script src="scripts/client.js" charset="utf-8"></script>
  <script src="scripts/services/realState.js" charset="utf-8"></script>


</head>

<body ng-app='myApp'>


  <div class="container-fluid">

    <div class="navBar">
      <h1>Weekend Challenge #5</h1>
      <button type="button" name="button"><a href="http://localhost:3000/#!/rent">See for rent</a></button>
      <button type="button" name="button"><a href="http://localhost:3000/#!/buy">See for sale</a></button>
      <button type="button" name="button"><a href="http://localhost:3000/#!/">post rent/sale</a></button>

    </div>
    <ng-view></ng-view>
    <h1>Post</h1>
    <div class="post">

      <label for="type">Type: </label>
      <select name='type' ng-model='dc.type'>
                    <option value="">Rent</option>
                    <option value="">Sell</option>
                </select>

      <button type="button" name="button" ng-click='dc.checkPost()'>Begin</button>
    </div>
  </div>
</body>

</html>

该应用程序未在此处运行,但基本上我没有在单击开始按钮时在默认控制器上获取日志。我不确定问题是什么。我应该在控制台'checkpost cliked'中看到

1 个答案:

答案 0 :(得分:0)

我想你忘了给angular-route.js。请通过添加以下脚本链接再次尝试

 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>
相关问题