我的模式页脚中有这个按钮:
<button class="btn btn-link" ng-click="run()">Create</button>
<小时/>
app.js
"use strict";
var myApp = angular.module('myApp', [], function($interpolateProvider,$httpProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
//Setting headers
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$httpProvider.defaults.headers.common['X-Requested-With'] = "XMLHttpRequest";
$httpProvider.defaults.headers.post['X-CSRF-TOKEN'] = $('meta[name=_token]').attr('content');
});
myApp.controller('skillController', function skillController($scope,$log,$http) {
$scope.run = function() {
console.log('RUNNN ----- ');
};
});
<小时/>
HTML
我有
<div class="row" ng-app="myApp" ng-controller="skillController" >
...
</div>
我无法得到这个
console.log('RUNNN ----- ');
在我的控制台上运行。
我应该检查什么?
最佳答案
问题是您没有将 $scope 传递给 Controller ,
myApp.controller('skillController', function skillController($scope) {
$scope.run = function($scope) {
alert('RUNNN ----- ');
};
});
演示
"use strict";
var myApp = angular.module('myApp', [], function() {});
myApp.controller('skillController', function skillController($scope) {
$scope.run = function($scope) {
alert('RUNNN ----- ');
};
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
</head>
<body ng-app="myApp" ng-controller="skillController" >
<button class="btn btn-link" ng-click="run()">Create</button>
</body>
</html>
关于javascript - 如何调试 ng-click 在模态中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42684831/