0
我想單擊我的按鈕時調用一個函數。這段代碼應該可以工作,但它不會觸發我在控制器中定義的函數。AngularJS - ng-click不會觸發我的控制器功能
代碼編譯正常,如控制檯顯示,任何想法?
謝謝!
這是我的代碼:
<html lang="en" ng-app="myApp" >
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ristorante Con Fusion</title>
<!-- Bootstrap -->
<script src="js/jquery-1.12.0.min.js"></script>
<script src="js/angular.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/mystyles.css" rel="stylesheet">
<script >
var app = angular.module('myApp', []);
app.controller('navCtrl', function($scope) {
$scope.select=function() {
alert('hi');
};
});
</script>
</head>
<body>
<nav id="mynav"class= "navbar navbar-inverse " role="navigation" ng-controller="navCtrl" >
<div class="container">
<ul class="nav navbar-nav color-white ">
<li >
<a id="home" ng-click="navCtrl.select()"href="#" >home</a></li>
<li >
<a id="1" href="#" ng-click="navCtrl.select() ">About</a></li>
<li >
<a id="2" href="#" ng-click="navCtrl.select() ">Contact</a></li>
</ul>
</div>
</nav>
</body>
我想你只需要使用select()而不是navCtrl.select() –