ng-click 不触发事件。尝试了大多数以前的 post 推荐
ng-click not firing event. tried most previous post recommendation
我正在尝试 运行 一个在 ng-click 按钮上的函数。我已经尝试了很多东西,但似乎仍然没有用。我的功能附加到范围。
我正在尝试 运行 一个按钮的 ng-click 函数。我已经尝试了很多东西,但似乎仍然没有用。我的功能附加到范围。
我正在尝试 运行 一个按钮的 ng-click 函数。我已经尝试了很多东西,但似乎仍然没有用。我的功能附加到范围。
我正在尝试 运行 一个按钮的 ng-click 函数。我已经尝试了很多东西,但似乎仍然没有用。我的功能附加到范围。
我正在尝试 运行 一个按钮的 ng-click 函数。我已经尝试了很多东西,但似乎仍然没有用。我的功能附加到范围。
我正在尝试 运行 一个按钮的 ng-click 函数。我已经尝试了很多东西,但似乎仍然没有用。我的功能附加到范围。
var app= angular.module('mainApp', []);
app.controller('institutions',function ($scope, $http) {
$scope.map;
$scope.schools;
$scope.markers=[];
$scope.myLatLng={lat: 43.6532, lng: -79.3832};
$http.get('data/institutions001.json')
.then(function (response) {
$scope.schools = response.data.institutions;
})
.then(function () {
$scope.map = new google.maps.Map(document.getElementById('stationMap'), {
center: $scope.myLatLng,
zoom: 7,
mapTypeId: 'roadmap'
});
$scope.addMarker( $scope.schools)
});
$scope.addMarker=function (places) {
$scope.markers = [];
$.each(places, function (key, value) {
var marker = new google.maps.Marker({
position: {lat: value.latitude, lng: value.longitude},
map: $scope.map,
title: value.el_name
});
$scope.markers.push(marker)
});
};
$scope.removeMarkers= function () {
console.log("working")
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Canada Institution Guide</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<!--angular js-->
<script src="js/angular.min.js"></script>
<script src="js/controller.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body ng-app="mainApp">
<nav class="navbar navbar-default">
<div class="container-fluid">
<a href="#" class="navbar-brand">Ontario Institution Guide</a>
<ul class="nav navbar-nav">
<li role="presentation" class="active"><a href="#">Home</a></li>
<li role="presentation"><a href="utilities.html">Utilities</a></li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid">
<div id="stationMap">
</div>
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading"></div>
<div class="panel-body">
<div class="row">
<div class="input-group col-sm-3 pull-left">
<span class="input-group-addon" id="basic-addon1">Filter by Name</span>
<input type="text" class="form-control" placeholder="Name" ng-model="globalFiter.el_name" aria-describedby="basic-addon1">
</div>
<div class="input-group col-sm-3 pull-left">
<span class="input-group-addon" id="basic-addon3">Filter by Type</span>
<input type="text" class="form-control" placeholder="type" ng-model="globalFiter.el_type" aria-describedby="basic-addon3">
</div>
<div class="input-group col-sm-3 pull-left">
<span class="input-group-addon" id="basic-addon2">Filter by Address</span>
<input type="text" class="form-control" placeholder="Address" ng-model="globalFiter.Address" aria-describedby="basic-addon2">
</div>
<div class="input-group col-sm-2 pull-right">
<button class="btn btn-primary" ng-click="removeMarkers()">Show on Map</button>
</div>
</div>
</div>
<!-- Table -->
<div class="table-responsive pre-scrollable" id="tableContainer" ng-controller="institutions">
<table class="table table-striped">
<thead>
<tr>
<th>S/N</th>
<th>Code</th>
<th>School Name</th>
<th>Type</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<!--loop-->
<tr ng-repeat="school in (filteredItems=(schools | filter:globalFiter))">
<td>.</td>
<td>{{school.el_code}}</td>
<td>{{school.el_name}}</td>
<td>{{school.el_type}}</td>
<td>{{school.Address}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<!--<script src="js/mapScript.js"></script>-->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDxEAx_VywfcUk7qOWyKnr9W1Jyoe3g7g8" ></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
您使用 ng-click="removeMarkers()"
的代码块未附加到任何范围。直到稍后,您才将控制器附加到 <table>
元素上。
如果您将 ng-controller=".."
指令移到 DOM 树中更高的位置,您的代码应该会按预期工作。例如在 <body
元素上。
<body ng-app="mainApp" ng-controller="institutions">
我正在尝试 运行 一个在 ng-click 按钮上的函数。我已经尝试了很多东西,但似乎仍然没有用。我的功能附加到范围。 我正在尝试 运行 一个按钮的 ng-click 函数。我已经尝试了很多东西,但似乎仍然没有用。我的功能附加到范围。 我正在尝试 运行 一个按钮的 ng-click 函数。我已经尝试了很多东西,但似乎仍然没有用。我的功能附加到范围。 我正在尝试 运行 一个按钮的 ng-click 函数。我已经尝试了很多东西,但似乎仍然没有用。我的功能附加到范围。 我正在尝试 运行 一个按钮的 ng-click 函数。我已经尝试了很多东西,但似乎仍然没有用。我的功能附加到范围。 我正在尝试 运行 一个按钮的 ng-click 函数。我已经尝试了很多东西,但似乎仍然没有用。我的功能附加到范围。
var app= angular.module('mainApp', []);
app.controller('institutions',function ($scope, $http) {
$scope.map;
$scope.schools;
$scope.markers=[];
$scope.myLatLng={lat: 43.6532, lng: -79.3832};
$http.get('data/institutions001.json')
.then(function (response) {
$scope.schools = response.data.institutions;
})
.then(function () {
$scope.map = new google.maps.Map(document.getElementById('stationMap'), {
center: $scope.myLatLng,
zoom: 7,
mapTypeId: 'roadmap'
});
$scope.addMarker( $scope.schools)
});
$scope.addMarker=function (places) {
$scope.markers = [];
$.each(places, function (key, value) {
var marker = new google.maps.Marker({
position: {lat: value.latitude, lng: value.longitude},
map: $scope.map,
title: value.el_name
});
$scope.markers.push(marker)
});
};
$scope.removeMarkers= function () {
console.log("working")
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Canada Institution Guide</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<!--angular js-->
<script src="js/angular.min.js"></script>
<script src="js/controller.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body ng-app="mainApp">
<nav class="navbar navbar-default">
<div class="container-fluid">
<a href="#" class="navbar-brand">Ontario Institution Guide</a>
<ul class="nav navbar-nav">
<li role="presentation" class="active"><a href="#">Home</a></li>
<li role="presentation"><a href="utilities.html">Utilities</a></li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid">
<div id="stationMap">
</div>
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading"></div>
<div class="panel-body">
<div class="row">
<div class="input-group col-sm-3 pull-left">
<span class="input-group-addon" id="basic-addon1">Filter by Name</span>
<input type="text" class="form-control" placeholder="Name" ng-model="globalFiter.el_name" aria-describedby="basic-addon1">
</div>
<div class="input-group col-sm-3 pull-left">
<span class="input-group-addon" id="basic-addon3">Filter by Type</span>
<input type="text" class="form-control" placeholder="type" ng-model="globalFiter.el_type" aria-describedby="basic-addon3">
</div>
<div class="input-group col-sm-3 pull-left">
<span class="input-group-addon" id="basic-addon2">Filter by Address</span>
<input type="text" class="form-control" placeholder="Address" ng-model="globalFiter.Address" aria-describedby="basic-addon2">
</div>
<div class="input-group col-sm-2 pull-right">
<button class="btn btn-primary" ng-click="removeMarkers()">Show on Map</button>
</div>
</div>
</div>
<!-- Table -->
<div class="table-responsive pre-scrollable" id="tableContainer" ng-controller="institutions">
<table class="table table-striped">
<thead>
<tr>
<th>S/N</th>
<th>Code</th>
<th>School Name</th>
<th>Type</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<!--loop-->
<tr ng-repeat="school in (filteredItems=(schools | filter:globalFiter))">
<td>.</td>
<td>{{school.el_code}}</td>
<td>{{school.el_name}}</td>
<td>{{school.el_type}}</td>
<td>{{school.Address}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<!--<script src="js/mapScript.js"></script>-->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDxEAx_VywfcUk7qOWyKnr9W1Jyoe3g7g8" ></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
您使用 ng-click="removeMarkers()"
的代码块未附加到任何范围。直到稍后,您才将控制器附加到 <table>
元素上。
如果您将 ng-controller=".."
指令移到 DOM 树中更高的位置,您的代码应该会按预期工作。例如在 <body
元素上。
<body ng-app="mainApp" ng-controller="institutions">