テンプレートemployee
のコントローラーからオブジェクトのリストを作成しようとしています。empctrl
コントローラーは次のとおりです。
app.controller('employeeController', function ($scope, employeeService) {
this.employees = {};
this.populateTable = function (data) {
this.employees = data;
};
var error = function (err) {
console.log("Error: " + err);
};
// Call Service to List all Employees
console.log("Service called to populate table.");
employeeService.output().then(this.populateTable, error);
this.populateTable();
});
ただし、私が書いたこのコードは機能しません。
<div ng-repeat="employee in empctrl.employees.allEmployees" class="table_row">
<div class="table_column" style="width:2%">{{ $index + 1 }}</div>
<div class="table_column" style="width:8%">{{ employee.employeeName}}</div>
<!-- 7 more columns -->
</div>
UI には何も表示されません。
代わりに$scope.employees
、コントローラーに書き込むと、次のように機能します。
<div ng-repeat="employee in employees.allEmployees" class="table_row">
$scope.<everything>
コントローラーで行うのがいかに魅力的であるかを知っているので$scope
、できるだけ使用しないようにしています。
誰かが and の適切な使用法と違いを示すことができれば( $scope
whereはコントローラーのエイリアスです)、感謝します。alias.abc
$scope.abc
alias
編集:まったく同じ質問です: 'this' vs $scope in AngularJS controllers
このリンクをありがとう、PankajParkar。