我正在尝试将AngularJS集成到我的Ruby On Rails应用程序中,但是当我这样做时,AngularJS无法识别。
以下是我的Javascript文件。
/assets/javascripts/application.js
//= require angular
//= require_tree ./angular
/assets/javascripts/angular/pallets.js
var app = angular.module('setPoints', []);
app.controller('pointCtrl', function($scope) {
$scope.initials = function() {
return $scope.origin.charAt(0) + $scope.end_point.charAt(0)
}
});
我还从https://code.angularjs.org/
下载了angular.js和angular-mocks.js这就是我试图将其称为应用程序的地方。
视图/货盘/ _form.html.erb
<div ng-app="setPoints" ng-controller="pointCtrl">
<td>{{initials()}}<%= id %></td>
<td><%= select(:pallet, :starting_point, select_options, :ng => {:model => "origin"}) %></td>
<td><%= select(:pallet, :destination, select_options, :ng => {:model => "end_point"}) %></td>
</div>
页面的输出只是{{initials()}} 1而不是它应该是什么。
当我检查页面源时,脚本看起来像这样。
<script src="/assets/angular.self-649179d58f3f4fbcbbe6a2ce7aad77642c6ff28734d531a57e415bea7d8214f6.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/angular/pallets.self-c14bf66f153614a582c54afa623e187c7b123469c25df99f576e9d130d7b403d.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/application.self-624ae67626e4a5ceec5f86543694500e04c25f404d2959217eab0ada97ee3895.js?body=1" data-turbolinks-track="true"></script>
答案 0 :(得分:0)
JS文件应位于app/assets/javascripts/
目录中。
你把它放在错误的地方。