ng-click
按钮不起作用。为什么ng-click不会触发这个按钮?
有没有人看到下面的代码段有什么问题?
var locationModel = {
"City": "Alexandria",
"State": "State"
};
var locationApp = angular.module("locationApp", []);
locationApp.controller("locationCtrl", function($scope) {
$scope.newLocation = locationModel;
$scope.addLocation = function(state) {
console.log(state);
//$http.post("/Home/CreateLocation", newLocation).then(function (response) {
// console.log("Inserted", data);
//});
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<body ng-controller="locationCtrl">
<div>
<button class="btn btn-default" ng-click="addLocation('VA')">
Add
</button>
</div>
</body>
您在body标签的父级中有'ng-app =“locationApp”'属性吗?没有它,你的应用就无法运行。 –
你的html标签中是否有ng-app =“locationApp”,因为它不在体上? @Sam – Yaser