Javascript 如何将编辑事件添加到此angular js应用程序?
拜托,我有这段代码,我不知道如何添加编辑事件和按钮。需要帮忙吗Javascript 如何将编辑事件添加到此angular js应用程序?,javascript,angularjs,Javascript,Angularjs,拜托,我有这段代码,我不知道如何添加编辑事件和按钮。需要帮忙吗 <script> var firstApp = angular.module('firstApp', []); firstApp.controller('FirstController', function($scope) { $scope.toic = ''; $scope.discussion = ''; $scope.updateMessage = function() {
<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>
var firstApp=angular.module('firstApp',[]);
firstApp.controller('FirstController',函数($scope){
$scope.toic='';
$scope.discussion='';
$scope.updateMessage=function(){
$scope.heading=$scope.topic;
$scope.body=$scope.discussion;
};
});
点击
{{heading}}
{{Body}}
您很接近,但您有一些打字错误和信息缺失,导致此功能无法正常工作:
1) 您需要将HTML包装在具有ng app
和ng controller
属性的元素中,以便angular知道将哪个模块/控制器用于绑定中的逻辑
2) $scope.toic
应该是$scope.topic
3) {{Body}}
应该是{{Body}
4)
应该是
(结束标记上缺少/
)
var firstApp=angular.module('firstApp',[]);
firstApp.controller('FirstController',函数($scope){
$scope.topic='';
$scope.discussion='';
$scope.updateMessage=function(){
$scope.heading=$scope.topic;
$scope.body=$scope.discussion;
};
});代码>
点击
{{heading}}
{{body}}
你好!stackoverflow社区乐于帮助开发人员实现他们的目标,前提是首先帮助自己。在这方面,请查看此[链接][1],以帮助您更好地阐述您的问题,展示您的工作,并帮助我们为您提供总体帮助。谢谢[1] :您没有ng app
或ng controller
属性,因此不会发生绑定。尝试用
包装您的输入和div,同时,$scope.toic
不会显示在绑定到主题的输入中,因为它们的拼写不同