【发布时间】:2017-08-20 01:41:21
【问题描述】:
我有一个文本框,它使用ng-model=sampleValue 连接到 Angular js
现在,我的要求是每当我单击按钮时都应该执行显示功能,并且应该将文本框的值更改为 Harish。但这不是我得到的结果。请看一下我在下面写的代码:
var app = angular.module("myApp", [])
app.controller("mainController", [ "$scope", function($scope){
$scope.show = function(){
$scope.sampleValue = "Harish";
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body ng-app = "myApp">
<input ng-controller="mainController" type="text" ng-model="sampleValue"/>
<button ng-click="show()">Click Here</button>
</body>
提前谢谢你:)
【问题讨论】:
标签: javascript html angularjs model-view-controller angular-ngmodel