2016-05-28 48 views
0

我已经在controller.js.的一个作用域中存储了一个值,以便在html文件中获取该作用域值。如何获取从controller.js文件中的值到angularjs中的html文件

Controller.js

myAppCont.controller('Listvalue',['$scope','$rootScope','$http', 
function($scope,$rootScope,$http){ 

     city=$scope.val; 
}]); 

HTML

<div class="col-md-10" ng-controller="Listvalue"> 
<table class="table table-bordered table-style" id="statusTable"> 
    <thead> 
    <tr> 
    <th>values</th> 
    </tr> 
    </thead> 
    <tbody class="align-center"> 
    <tr> 
    <td>{{city}}</td> 
    </tr> 
    </tbody> 
    </table> 
    </div> 

回答

0

你需要有控制器内部的$范围变量,就做别的办法

myAppCont.controller('Listvalue',['$scope','$rootScope','$http', 
function($scope,$rootScope,$http){ 
     $scope.city=val; 
}]); 

然后它会进行评估,并显示在视图

<td>{{city}}</td> 

工作Sample

+0

@Divakar检查样本 – Sajeetharan

0

角具有2个数据绑定原理。您与模型绑定的数据会反映在视图中。

使用$ scope访问相应控制器中的模型。

无论您希望绑定到视图的数据应该通过$ scope。

在这种情况下,如果你有,已经存储的数据在$scope.val

绑定,为您的看法,

<td>{{val}}</td> 

这应该工作!

相关问题