Ruby on rails 在小示例中绑定丢失(单击后)
我在Angular JS中有一个非常小的应用程序。它被放在一个更大的rails应用程序中,但我看不到太多的交互。angular应用程序允许用户与一组类别交互。简单到:Ruby on rails 在小示例中绑定丢失(单击后),ruby-on-rails,angularjs,Ruby On Rails,Angularjs,我在Angular JS中有一个非常小的应用程序。它被放在一个更大的rails应用程序中,但我看不到太多的交互。angular应用程序允许用户与一组类别交互。简单到: var angular_app = angular.module('angular_app', []); angular_app.config(['$httpProvider', function($httpProvider, $cookieStore) { //Protection }]); angular_app.cont
var angular_app = angular.module('angular_app', []);
angular_app.config(['$httpProvider', function($httpProvider, $cookieStore) {
//Protection
}]);
angular_app.controller('CategoriesController', function ($scope, $http) {
$scope.isEditing = false;
$scope.categoryName = '';
$http.get('/api/categories').success(function(data) {
//We use this to data-bind with the HTML placed below
$scope.categories = data;
});
$scope.addNewCategory = function() {
...
}
$scope.editCategory = function(index) {
if (!index)
return;
var selectedCategory = $scope.categories[index];
// With ng-show, we make visible the part of the UI
// that should be used for editing
$scope.isEditing = true;
}
$scope.cancelEditCategory = function() {
$scope.isEditing = false;
}
$scope.deleteCategory = function(index) {
...
}
});
angular.element(document).ready(function() {
angular.bootstrap(document, ['angular_app']);
});
我们的想法是,信息显示在一个列表中,我们有一个“编辑”按钮,允许用户查看UI的其他部分,以便执行更改
<div ng-controller="CategoriesController">
<div ng-show='isEditing' class="popup_menu">
DIV FOR EDITING
</div>
<ul>
<li ng-repeat="category in categories">
<a href="#" ng-click='deleteCategory($index)'>[X]</a>
<a href="#" ng-click='editCategory($index)'>[E]</a>{{ category.name }}
</li>
</ul>
<input type="text" id="categoryTextBox" ng-model="categoryName"/>
<button id="submit" ng-click='addNewCategory()'>New category</button>
</div>
当必须显示时:
[X] [E]computer science
[X] [E]politics
[X] [E]news
(这是我在范围内拥有的)。它发生在点击几下之后(并持续一秒钟)控制台上没有错误,没有与其他库的交互(据我所知)
谢谢 涡轮链接 我在
角度方面没有经验,但也许你的问题在于-这是Rails只加载页面的
标记的一种方式-保持
完好无损
TurboLink因Rails上的Javascript而臭名昭著,因为每次在不重新加载页面的
部分的情况下重新加载
,所有JS绑定都将消失。在普通JS中,解决此问题的方法是使用文档
对象并从中委托:
$(document).on("action", "delegated_object", function(){
...
});
如果这不起作用,我深表歉意-这对我们来说是一个常见的问题,但由于我没有使用Angular
的经验,我不知道这是否会对您有所帮助。似乎我应该更加小心使用以下链接:
<a href="#" ng-click='deleteCategory($index)'>[X]</a>
<a href="#" ng-click='editCategory($index)'>[E]</a>{{ category.name }}
{{category.name}
我不知道这是如何工作的,但是如果链接有他的href属性,那么会针对127.0.0.1发出GET请求,以某种方式破坏了角度代码。如果你这样说:
<a ng-click='deleteCategory($index)'>[X]</a>
<a ng-click='editCategory($index)'>[E]</a>{{ category.name }}
[X]
[E] {{category.name}
这个问题会解决的。谢谢大家的阅读和帮助 有关错误,请参阅浏览器控制台日志。谢谢!,但是错误日志是空的。我支持这个答案。Turbolink是新的恶魔,禁用它并快乐地生活。
<a ng-click='deleteCategory($index)'>[X]</a>
<a ng-click='editCategory($index)'>[E]</a>{{ category.name }}