在角度railscasts教程中,我有一个带有angularjs-rails的rails应用程序, angular.js和angular-resource.js都包含在我的html文件的头部。
我的欢迎#index.html.erb是:
<h1>Welcome</h1>
<div id="search" ng-controller="SearchCtrl">
<form ng-submit="search()">
<input type="text" ng-model="newSearch.postcode">
<input type="submit" value="Search">
</form>
<ul>
<li ng-repeat="trader in traders">
{{trader.name}}
</li>
</ul>
</div>
和我的welcome.js.coffee:
app = angular.module("Search", ["ngResource"])
@SearchCtrl = ($scope, $resource) ->
$scope.traders = [
{name: "Jonlee"}
{name: "Johnny"}
]
$scope.search = ->
console.log($scope.newSearch.postcode)
由于某种原因,资源无法正常工作,我收到以下错误:
[$injector:unpr] Unknown provider: $resourceProvider <- $resource
已经用Google搜索并看到了这个错误,但是在更复杂的例子中并没有真正适合这个问题。
的application.js:
//= require angular
//= require angular-resource
//= require_tree .
导出welcome.js:
(function() {
var app;
app = angular.module("Search", ["ngResource"]);
this.SearchCtrl = function($scope, $resource) {
$scope.traders = [
{
name: "Jonlee"
}, {
name: "Johnny"
}
];
return $scope.search = function() {
return console.log($scope.newSearch.postcode);
};
};
}).call(this);