请问,我有这段代码,而且我对如何添加编辑事件和按钮感到茫然。有什么帮助吗?
<script>
var firstApp = angular.module('firstApp', []);
firstApp.controller('FirstController', function($scope) {
$scope.toic = '';
$scope.discussion = '';
$scope.updateMessage = function() {
$scope.heading = $scope.topic;
$scope.body = $scope.discussion;
};
});
</script>
<input ng-model="topic">
<input ng-model="discussion">
<button ng-click="updateMessage()">click<button>
<div>
{{heading}}
{{Body}}
</div>
答案 0 :(得分:1)
你很接近,但是你有一些错别字和丢失的信息导致它无效:
1)您需要将HTML包装在具有ng-app
和ng-controller
属性的元素中,以便angular知道哪个模块/控制器用于绑定中的逻辑。
2)$scope.toic
应为$scope.topic
3){{Body}}
应为{{body}}
4)<button ...><button>
应为<button ...></button>
(在结束标记时丢失/
)
var firstApp = angular.module('firstApp', []);
firstApp.controller('FirstController', function($scope) {
$scope.topic = '';
$scope.discussion = '';
$scope.updateMessage = function() {
$scope.heading = $scope.topic;
$scope.body = $scope.discussion;
};
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="firstApp" ng-controller="FirstController">
<input ng-model="topic">
<input ng-model="discussion">
<button ng-click="updateMessage()">click</button>
<div>{{heading}}
{{body}} </div>
</div>
&#13;