只需要解释为什么这不起作用?我试图从教程点开始遵循教程。第一个和第二个模型工作正常。但不适用于第三种型号。有人可以向我解释为什么它不起作用吗?提前致谢。
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
..........
<body ng-app="mainApp" ng-controller="machineController">
<input type="text" ng-model="anyText.first" placeholder="any text here" />
<input type="text" ng-model="anyText.second" placeholder="any text here" />
<span>{{ anyText.third() }}</span>
<script>
var app = angular.module("mainApp", []);
app.controller('machineController', function($scope) {
$scope.anyText = {
first: "This is first default text",
second: "This is second default text",
third: function() {
$object = $scope.anyText;
var newtext = anyText.first + " ::: " + anyText.second;
return newtext;
}
};
});
</script>
</body>
最佳答案
您必须替换此行
var newtext = anyText.first + ":::"+ anyText.second;
与
var newtext = $object.first + " ::: " + $object.second;
as anyText
变量未定义
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
<body ng-app="mainApp" ng-controller="machineController">
<input type="text" ng-model="anyText.first" placeholder="any text here"/>
<input type="text" ng-model="anyText.second" placeholder="any text here"/>
<span>{{ anyText.third() }}</span>
<script>
var app = angular.module("mainApp", []);
app.controller('machineController',function($scope){
$scope.anyText = {
first: "This is first default text",
second: "This is second default text",
third: function(){
$object = $scope.anyText;
var newtext = $object.first + " ::: " + $object.second;
return newtext;
}
};
});
</script>
</body>
关于javascript - AngularJS 启动器卡住了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46597724/