試圖學習angularjs只是因爲但沒有得到基礎知識。 爲什麼不能工作? 'hello'被綁定,並且如果未註釋,將顯示「正在工作」。簡單的angularjs將服務數據注入控制器
angular.module('myApp', [])
.service('formService', function() {
this.names = ['John', 'James', 'Jake'];
}).controller('FormCtrl', ['$scope', function ($scope, formService) {
$scope.hello = formService.names[1];//"working";
}]);
[HTML片段]
<div ng-app="myApp" ng-controller="FormCtrl">
{{hello}}
</div>