Angularjs 角度装订误差
我的angular应用程序有一个奇怪的错误 我有一个控制器,在这里我声明了一些变量。如果我要在html中编写它们,它将按预期工作。但如果我试图改变它们(如在输入框中),什么也不会发生 即使当我试图通过按钮或其他方式调用函数时,也不会发生任何事情。 下面的代码是我的控制器的简化版本Angularjs 角度装订误差,angularjs,binding,Angularjs,Binding,我的angular应用程序有一个奇怪的错误 我有一个控制器,在这里我声明了一些变量。如果我要在html中编写它们,它将按预期工作。但如果我试图改变它们(如在输入框中),什么也不会发生 即使当我试图通过按钮或其他方式调用函数时,也不会发生任何事情。 下面的代码是我的控制器的简化版本 angular.module('myModule', []) .controller('myCtrl', ['$rootScope', '$scope', 'SomeServices', function ($
angular.module('myModule', [])
.controller('myCtrl', ['$rootScope', '$scope', 'SomeServices',
function ($rootScope, $scope, someServices) {
'use strict';
$scope.myVar = "foobar";
$scope.myFunction = function() {
// it never gets here
}
$scope.$watch("myVar", function() {
// it even never gets here
});
}]);
我的HTML
<!-- change this and the watcher will not doing anything -->
<!-- the value will bee foobar, but after that nothing happens -->
<input type="text" ng-model="myVar" />
<button ng-click="myFunction()">click here and nothing will happen</button>
点击这里,什么也不会发生
如果我在codepen中尝试,它会正常工作。
有人有过这样的行为吗?我看不出为什么它不起作用有什么问题,可能这是更简单的演示
var-app=angular.module('myApp',[]);
应用程序控制器('MainCtrl',函数($scope){
$scope.myVar=“foobar”;
$scope.myFunction=function(){
log($scope.myVar+'myFunction called')
}
$scope.$watch(“myVar”,function()){
console.log($scope.myVar+'value changed')
});
});代码>
点击这里,什么也不会发生
正如我所写的-错误是什么也没发生。好像装订不好似的。我会想得更清楚一点。等等,请出示你的html,完整的html,好的。我已经编辑了条目。如果在该函数中没有输入任何内容,请将其粘贴到myfunction()$scope.myVar=“foobar”;或者单击按钮时,您想要什么?输入字段是否已预填充?