在js中的双向数据绑定

我正在使用nodejs + Angular和HTML作为一个froentend

这是我的HTML代码

<div id="container" ng-app='two_way' ng-controller='two_way_control'> <div class="row" ng-repeat="data in profile_pictures"> <div class=".col-sm-6 .col-md-5 .col-lg-6" style="background-color:#eee;height:150px;width:500px;margin-left:240px;margin-top:20px;"> <h4 style="padding:10px;">User Say's</h4><hr> <img src="{{data.profile_picture}}" class="img-circle" style="width:100px;height:100px;margin-left:-140px;margin-top:-130px;"> </div> </div> </div> 

和我的angular码在这里

 app.controller('two_way_control',function($scope,$http,$interval){ load_pictures(); $interval(function(){ load_pictures(); },300); function load_pictures(){ $http.get('http://localhost:3000/load').success(function(data){ $scope.profile_pictures=data; }); }; }); 

和我的服务器代码是

 app.get('/load',function(req,res){ connection.query("SELECT * from user_info",function(err,rows){ if(err) { console.log("Problem with MySQL"+err); } else { res.end(JSON.stringify(rows)); } }); }); 

哪个工作正常..

当我在** user_info *中input新logging时。 它会显示新的logging给我。

这是正确的方式做双向数据绑定或我失去了一些东西

请帮忙。

谢谢

它看起来好像你在做一种方式绑定,因为你的angular码永远不会修改表中的configuration文件图片(这意味着你没有没有表单域,你的页面是只读的)。 但是,AFAIK你做的一切都是正确的,一旦你添加编辑function到你的angular度页面,你会一直做双向绑定

是! Angular'2-way bind'在scope.variable和VIEW(input元素中的ng-model)之间。 在这种情况下,IMG元素的SRC属性需要用ng-src来设置! 因为IMG是在angular色主体脚本之前加载的html元素。

 <div id="container" ng-app='two_way' ng-controller='two_way_control'> <div class="row" ng-repeat="data in profile_pictures"> <div class=".col-sm-6 .col-md-5 .col-lg-6" style="background-color:#eee;height:150px;width:500px;margin-left:240px;margin-top:20px;"> <h4 style="padding:10px;">User Say's</h4><hr> <img ng-src="{{data.profile_picture}}" class="img-circle" style="width:100px;height:100px;margin-left:-140px;margin-top:-130px;"> </div> </div> </div>