I have this button in my modal footer :
<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
I have
<div class="row" ng-app="myApp" ng-controller="skillController" >
...
</div>
I couldn't get this
console.log('RUNNN ----- ');
to run on my console.
What should I look into?
Problem is you are not passing $scope to your controller,
myApp.controller('skillController', function skillController($scope) {
$scope.run = function($scope) {
alert('RUNNN ----- ');
};
});
DEMO
"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>
I have no idea of the function in the module function($interpolateProvider,$httpProvider)
, but if you delete this function, it will work well. I know angular.module('moduleName',[])
is used to create a new module, and angular.module('moduleName')
is to use an existing module. Can module()
method can have the third param?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.