gpt4 book ai didi

javascript - 无法将数据从 Controller 绑定(bind)到 View 。控制台没有错误

转载 作者:行者123 更新时间:2023-11-30 08:25:41 24 4
gpt4 key购买 nike

您好,我正在学习 Angular 并尝试将数据从模型绑定(bind)到 View 。但它没有抛出任何错误。你能帮帮我吗。

<div ng-app ="myApp" ng-controller="emp"> 
Hello {{emp.name}}, I am happy that you are getting a salary of{{emp.salary}}.
</div>

var app = angular.module("myApp", []);

app.controller('emp', function(){
this.name = "John";
this.salary = 4500;
});

请查找Fiddler

最佳答案

ng-controller="emp" 更改为 ng-controller="emp as emp"

<div ng-app ="myApp" ng-controller="emp as emp"> 
Hello {{emp.name}}, I am happy that you are getting a salary of{{emp.salary}}.
</div>

fiddle :https://jsfiddle.net/vedp/duhfgbb9/1/

关于javascript - 无法将数据从 Controller 绑定(bind)到 View 。控制台没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46128337/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com