我想我不明白什么.. 为什么我在控制台中看到“未定义”?
<script>
function Controller($scope) {
console.log($scope.name);
}
</script>
<body ng-app ng-controller="Controller">
<input type="text" value="3" ng-model="name">
</body>
最佳答案
Angular 不处理 value 属性。如果要将模型值初始化为输入中的某些值,则需要使用 ng-init
,f.ex.
<input ng-model="foo" ng-init="foo = 3">
关于javascript - 从 Controller 访问模型。 Angular .js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17285242/