<input type="text" ng-model="lastName" /> <!-- this textbox should be prefilled when screen load using ng-model only -->
angular.element(document).ready(function () {
console.log("is ready now");
$scope.lastName="ThisIsLastname"; //set value
console.log($scope.lastName); // I can see that value has been set successfully.
});
因此,当我重新加载页面时,一旦调用就绪函数,我可以看到该值已打印在控制台上,但是我可以看到空的文本框(姓氏的值未显示在文本框上。)>但是当我第一次单击该空白文本框,然后单击屏幕上的任何位置时,将显示文本框的值。我不明白是什么使它现在出现,但是在调用ready函数时没有出现。
我不需要替代解决方案,我想知道为什么会这样!
我正在准备函数中使用$ scope.lastName =“ ThisIsLastname”设置名为lastName的ng-model的值。我可以设置值,也可以设置它,因为我可以在控制台中看到它,但是问题是值...
您可以在分配$ scope.value以运行摘要周期后添加$ scope。$ apply()。
$timeout
包装代码以触发摘要循环: