【发布时间】:2014-06-04 14:32:49
【问题描述】:
我正在使用 Angular 开发一个 Rails 应用程序,过去,我一直使用 $scope 来访问 Angular 控制器的变量和方法。 看了 codeschool 的 Shaping up with Angular.js 课程后,我意识到 this 的使用和控制器的别名是访问它们的更好方法。
无论如何,我的应用在 $scope 上运行良好,但是当我更改为“this”实现时,laboratory var 变空了...
我在这里放了一些代码: html:
<div ng-controller="LaboratorioController as labCtrl">
<tr ng-repeat="laboratorio in labCtrl.laboratorios" >
<td>{{ laboratorio.nombre }}</td>
<td>{{ laboratorio.razon_social }}</td>
<td>{{ laboratorio.direccion }}</td>
角码:
(function() {
var app = angular.module('guiaV', []);
app.controller('LaboratorioController', function( $http) {
this.laboratorios = [];
return $http.get('./laboratorios.json').success(function(data) {
return this.laboratorios = data;
});
});
})();
有什么想法吗?
【问题讨论】:
-
@Blackhole 我已经看到了那个答案,但对我没有帮助......
-
所以这里有一个很好的提示:使用
$scope。真的。 -
与stackoverflow.com/questions/11605917/… 有类似的问题“标题”并不一定是重复的......快速审阅者也应该阅读内容。
标签: javascript ruby-on-rails angularjs