$ scope.man = “A”; //默认文字
<div ng-app="myApp" ng-controller="myCtrl">
<p>person clicked {{man}}</p>
<button ng-click="man('b')">B</button><br>
<button ng-click="man('c')">C</button>
</div>
var app=angular.module("myApp",[]);
app.controller("myCtrl",function($scope){
$scope.man="A";
$scope.man=function(value)
{
$scope.man=value;
}
});
我是angularjs的新手我想通过参数更改文本但是文本没有改变而且默认文本A也没有显示可以帮助我解决这个问题
答案 0 :(得分:0)
您的$ scope变量和函数是相同的。像这样改变你的功能,
<强> HTML:强>
<div ng-app="myApp" ng-controller="myCtrl">
<p>person clicked {{man}}</p>
<button ng-click="change('b')">B</button><br>
<button ng-click="change('c')">C</button>
</div>
<强>控制器:强>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.man = "A";
$scope.change = function(value) {
$scope.man = value;
}
});
<强> DEMO 强>