ng-click 在 div 中不起作用
ng-click not work in div
我被困在这里有一段时间了,当我使用 "form" 标签时一切正常,但在 "div" 标签中 ...
main.js:
var app = angular.module('demo', []);
app.controller('appctrl', function ($scope) {
$scope.start = function (name) {
console.log(name);}
}
index.html:
<!DOCTYPE html>
<html ng-app="demo">
<head>
<script src="js/angular.min.js"></script>
<script src="js/main.js"></script>
</head>
<body>
<div id="container" ng-controller="appctrl">
<input id="input" autocorrect="off" spellcheck="false" autocapitalize="off" autofocus="true" placeholder="Please enter your full name" type="text" ng-model="name">
<div id="button" ng-click="show()">Start Demo</div>
</div>
</body>
</html>
我认为你需要这个,你需要将函数命名为 show
,还需要将参数传递给函数 show.
此外,您的控制器中缺少 )
。
app.controller('appctrl', function ($scope) {
$scope.show = function (name) {
console.log(name);}
}
演示
var app = angular.module('demo', []);
app.controller('appctrl', function ($scope) {
$scope.start = function (name) {
console.log(name);
}
});
<!DOCTYPE html>
<html ng-app="demo">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
</head>
<body>
<div id="container" ng-controller="appctrl">
<input id="input" autocorrect="off" spellcheck="false" autocapitalize="off" autofocus="true" placeholder="Please enter your full name" type="text" ng-model="name">
<div id="button" ng-click="start('TEST')">Start Demo</div>
</div>
</body>
</html>
app.controller('appctrl', function ($scope) {
$scope.name = null;
$scope.show = function (name) {
console.log(name);
}
});
<div id="container" ng-controller="appctrl">
<input id="input" autocorrect="off" spellcheck="false" autocapitalize="off" autofocus="true" placeholder="Please enter your full name" type="text" ng-model="name">
<div id="button" ng-click="show(name)">Start Demo</div>
</div>
您正在调用 show()
但您定义了 start()
我被困在这里有一段时间了,当我使用 "form" 标签时一切正常,但在 "div" 标签中 ...
main.js:
var app = angular.module('demo', []);
app.controller('appctrl', function ($scope) {
$scope.start = function (name) {
console.log(name);}
}
index.html:
<!DOCTYPE html>
<html ng-app="demo">
<head>
<script src="js/angular.min.js"></script>
<script src="js/main.js"></script>
</head>
<body>
<div id="container" ng-controller="appctrl">
<input id="input" autocorrect="off" spellcheck="false" autocapitalize="off" autofocus="true" placeholder="Please enter your full name" type="text" ng-model="name">
<div id="button" ng-click="show()">Start Demo</div>
</div>
</body>
</html>
我认为你需要这个,你需要将函数命名为 show
,还需要将参数传递给函数 show.
此外,您的控制器中缺少 )
。
app.controller('appctrl', function ($scope) {
$scope.show = function (name) {
console.log(name);}
}
演示
var app = angular.module('demo', []);
app.controller('appctrl', function ($scope) {
$scope.start = function (name) {
console.log(name);
}
});
<!DOCTYPE html>
<html ng-app="demo">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
</head>
<body>
<div id="container" ng-controller="appctrl">
<input id="input" autocorrect="off" spellcheck="false" autocapitalize="off" autofocus="true" placeholder="Please enter your full name" type="text" ng-model="name">
<div id="button" ng-click="start('TEST')">Start Demo</div>
</div>
</body>
</html>
app.controller('appctrl', function ($scope) {
$scope.name = null;
$scope.show = function (name) {
console.log(name);
}
});
<div id="container" ng-controller="appctrl">
<input id="input" autocorrect="off" spellcheck="false" autocapitalize="off" autofocus="true" placeholder="Please enter your full name" type="text" ng-model="name">
<div id="button" ng-click="show(name)">Start Demo</div>
</div>
您正在调用 show()
但您定义了 start()