我正在尝试使用breeze执行使用angualar的$ http工作的相同调用。由于某种原因,$ scope似乎不适用于微风回调。
代码:
<!DOCTYPE html>
<html ng-app="">
<head>
<meta name="viewport" content="width=device-width" />
<title>App</title>
</head>
<body ng-controller="TextController">
<div>
<p>{{textData1}}</p>
<p>{{textData2}}</p>
<ul>
<li ng-repeat="patient in patients">
<span>{{patient.FirstName}}</span>
</li>
</ul>
</div>
<script src="/scripts/jquery-1.8.2.js"></script>
<script src="/scripts/q.js"></script>
<script src="/scripts/breeze.min.js"></script>
<script src="/Scripts/angular.js"></script>
<script type="text/javascript">
function TextController($scope, $http){
breeze.config.initializeAdapterInstance("modelLibrary", "backingStore", true);
var serviceName = "/api/breeze";
var manager = new breeze.EntityManager(serviceName);
var query = breeze.EntityQuery.from("Patients");
$scope.textData1 = "Waiting..";
$scope.textData2 = "Waiting..";
manager.executeQuery(query).
then(function (data) {
console.log(data);
$scope.textData1 = 'Breeze';
//$scope.patients = [];
//$scope.patients = data;
}).
fail(function(error) {
$scope.textData1 = error.message;
});
$http({ method: 'GET', url: '/api/patients' }).
success(function (data, status, headers, config) {
console.log(data);
$scope.textData2 = 'Angular';
//$scope.patients = [];
//$scope.patients = data;
}).
error(function (data, status, headers, config) {
});
}
</script>
</body>
</html>
在上面的代码中,当我将它打印到控制台时,angular $ http调用和breeze调用返回数据。当只运行textData2绑定更新为'Angular'时,textData1绑定不会更新为'Breeze'。我正在调用控制台的函数,但绑定不会更新。如果我尝试将数据列表绑定到范围中的“患者”引用,则会发生同样的事情。我评论说要显示我问题的最简单版本。
有意义吗?想法?
布赖恩