Javascript AngularJS中的控制器和ng模型指令

Javascript AngularJS中的控制器和ng模型指令,javascript,angularjs,Javascript,Angularjs,有以下代码: function MyController($scope) { $scope.name = 'John'; $scope.show = true; } <div ng:app> <form name="form" ng-controller="MyController"> <div data-ng-switch="show"> <input data-ng-switch-when="true" type="text"

有以下代码:

function MyController($scope) {
 $scope.name = 'John';
 $scope.show = true;
}
<div ng:app>
 <form name="form" ng-controller="MyController">
   <div data-ng-switch="show">
     <input data-ng-switch-when="true" type="text" data-ng-model="name" />
   </div>
   Name: {{name}} 
 </form>
</div>
函数MyController($scope){
$scope.name='John';
$scope.show=true;
}
名称:{{Name}

它的代码工作起来很奇怪:当我的视图被加载后,我看到输入值为“John”时,它就很好了。但当我试图在字段中输入一些新值时,我的{{name}}输出并没有改变。为什么

我认为你应该修改你的语法,例如ng:app?看起来怪怪的
ng开关
创建自己的作用域,所以当您在输入中更改时,您会更改嵌套作用域中的值。您可以尝试将其更改为
$scope.user={name:“John”}
,以及
datang model=“user.name”
name:{{{user.name}}
Grundy-是的,它可以工作,但我不明白为什么。你能给出一个详细的答案吗?@malcoauri用谷歌“角点规则”来解释。这只是原型继承的正常javascript行为。@HEPİMİZYARBAYMEHMETALKANIZ这是有效的语法,以及
data-ng-app
x-ng-app