refresh when clicked on link with actual url

I use routeProvider to define controlers and templates for my urls. When I click on the link, which has the same url as is the actual location, nothing happens. I would like the reload() method to be called if a user clicks on such a link even if the location hasn't changed. In other words, if I set the location to the same value, I would like it to behave the same as if I would set it to

刷新时点击链接与实际的网址

我使用routeProvider为我的url定义控制器和模板。 当我点击与实际位置相同的链接时,没有任何反应。 如果用户点击这样的链接,即使位置没有改变,我也会调用reload()方法。 换句话说,如果我将位置设置为相同的值,我希望它的行为与我将它设置为不同的值相同。 有没有办法配置routeProvider或locationProvider自动执行它? 或者什么是正确的做法呢? 这是往返应用程序中的stadard行为,但如何在angularjs中执行此操作?

Pass variables to AngularJS controller, best practice?

I am brand new to AngularJS and like what I've seen so far, especially the model / view binding. I'd like to make use of that to construct a simple "add to basket" piece of functionality. This is my controller so far: function BasketController($scope) { $scope.products = []; $scope.AddToBasket = function (Id, name, price, image) { ... }; } And this is

将变量传递给AngularJS控制器,最佳实践?

我是AngularJS的全新产品 ,就像我目前看到的,特别是模型/视图绑定。 我想利用它来构建一个简单的“添加到篮子”功能块。 到目前为止,这是我的控制器: function BasketController($scope) { $scope.products = []; $scope.AddToBasket = function (Id, name, price, image) { ... }; } 这是我的HTML: <a ng-click="AddToBasket('237', 'Laptop', '499.95', '237.png')">Add to basket</a

Angular directive with default options

I'm just starting with angularjs, and am working on converting a few old JQuery plugins to Angular directives. I'd like to define a set of default options for my (element) directive, which can be overridden by specifying the option value in an attribute. I've had a look around for the way others have done this, and in the angular-ui library the ui.bootstrap.pagination seems to do s

带默认选项的Angular指令

我刚刚开始使用angularjs,并且正在将几个旧的JQuery插件转换为Angular指令。 我想为我的(element)指令定义一组默认选项,可以通过在属性中指定选项值来覆盖这些选项。 我查看了其他人做这件事的方式,在angular-ui库中,ui.bootstrap.pagination似乎做了类似的事情。 首先,所有的默认选项都在一个常量对象中定义: .constant('paginationConfig', { itemsPerPage: 10, boundaryLinks: false, ... }) 然后将一个

Call method in directive controller from other controller

I have a directive that has its own controller. See the below code: var popdown = angular.module('xModules',[]); popdown.directive('popdown', function () { var PopdownController = function ($scope) { this.scope = $scope; } PopdownController.prototype = { show:function (message, type) { this.scope.message = message; this.scope.type = type;

从其他控制器调用指令控制器中的方法

我有一个有自己的控制器的指令。 请看下面的代码: var popdown = angular.module('xModules',[]); popdown.directive('popdown', function () { var PopdownController = function ($scope) { this.scope = $scope; } PopdownController.prototype = { show:function (message, type) { this.scope.message = message; this.scope.type = type; }, hi

Difference between the 'controller', 'link' and 'compile' functions when defining a directive

Some places seem to use the controller function for directive logic and others use link. The tabs example on the angular homepage uses controller for one and link for another directive. What is the difference between the two? I'm going to expand your question a bit and also include the compile function. compile function - use for template DOM manipulation (ie, manipulation of tElement =

定义指令时,“控制器”,“链接”和“编译”功能之间的区别

有些地方似乎将控制器功能用于指令逻辑,而其他地方则使用链接。 角度主页上的选项卡示例将控制器用于一个,并链接另一个指令。 两者有什么区别? 我将扩展你的问题,并且还包括编译功能。 编译函数 - 用于模板 DOM操作(即,tElement = template元素的操作),因此适用于与指令相关联的模板的所有DOM克隆的操作。 (如果你还需要一个链接函数(或者前后链接函数),并且你定义了一个编译函数,编译函数必须返回链接函数

Angular sharing data between controllers using service

I'm using service to share data between controllers. In first controller I call function like this: muscleGroupService.setState(true); Here is code for function in service : var state; function setState(x) { state = x; } x becomes true, but for some reason state doesn't become true, it stays undefined. How can I fix this ? Edit I believe I've managed to fin

使用服务的控制器之间的角度共享数据

我正在使用服务在控制器之间共享数据。 在第一个控制器中,我调用这样的函数: muscleGroupService.setState(true); 以下是服务中功能的代码: var state; function setState(x) { state = x; } x成为真,但由于某种原因,状态不会变为真,它保持不确定状态。 我怎样才能解决这个问题 ? 编辑 我相信我已经设法找到问题所在,但我不知道如何解决问题。 在Index.html中我有这行代码: <div clas

Angular JS factory vs service vs provider by example

I know this question has been asked and answers have been given. But I learn best through practical examples and I came across code that I didn't fully understand. I'm referring to Angular Strap which is an awesome set of directives for cool user interactions: http://mgcrea.github.io/angular-strap/ I was looking at the code for the tooltip feature and saw that the author was using a

Angular JS工厂vs服务与供应商的例子

我知道这个问题已经被问及已经给出了答案。 但我通过实际的例子学得最好,并且遇到了我没有完全理解的代码。 我指的是Angular Strap,它是一组非常酷的用户交互指令:http://mgcrea.github.io/angular-strap/ 我正在查看工具提示功能的代码,并看到作者正在使用提供程序来公开功能。 他是否也可以使用服务或工厂来完成同样的工作? 或者是提供者必需的? 这里是代码的链接:https://github.com/mgcrea/angular-strap/b

dynamic pages, same template, how to access and load article by id

I am slightly puzzled on how to use angularjs to build a blog-like web site. If you think of an ordinary blog,,, and say,, I am building it using php and mysql.. what I don't understand is how do I make angular get an article based on id.. I can load data for a list of all articles.. I can load data for a single page (from a static json),, I understand how to send http requests,, but how

动态页面,相同模板,如何通过ID访问和加载文章

我对如何使用angularjs构建一个类似博客的网站略感困惑。 如果你想到一个普通的博客,,,说,我正在建设它使用PHP和MySQL ..我不明白的是如何使棱角得到一篇基于ID的文章.. 我可以加载数据的所有文章的列表..我可以加载数据的单个页面(从静态json),,我知道如何发送http请求,但我如何访问 mysite.com/page?id=1 or mysite.com/page?id=2 or mysite.com/page?id=3 很明显,我想为每个单独的博客文章加载相同的模板..但我

Angularjs Best Practice for Data Store

My angular app have 2 controllers. My problem is that the controllers does not keep the data when the user navigates away from the page. How can I store the selected data on of my controllers into a data store so it can be used between other controllers? Option 1 - custom service You can utilize a dedicated angular service to store and share data between controllers (services are single in

Angularjs数据存储最佳实践

我的角度应用有2个控制器。 我的问题是,当用户离开页面时,控制器不保存数据。 如何将我的控制器上的选定数据存储到数据存储器中,以便可以在其他控制器之间使用? 选项1 - 定制service 您可以利用专用的角度服务在控制器之间存储和共享数据(服务是单个实例对象) 服务定义 app.service('commonService', function ($http) { var info; return { getInfo: getInfo, setI

Use underscore inside Angular controllers

How do I use underscore library inside angularjs controllers? On this post: AngularJS limitTo by last 2 records somebody suggested to assign an _ variable to the rootScope so that the library will be available to all the scopes within the app. But I'm not clear where to do it. I mean should it go on the app module declaration? ie: var myapp = angular.module('offersApp', [])

在Angular控制器中使用下划线

如何在angularjs控制器中使用下划线库? 在这篇文章中:AngularJS limitTo最后2条记录有人建议将_变量分配给rootScope,以便该库可用于应用程序内的所有范围。 但我不清楚在哪里做。 我的意思是应该继续应用程序模块声明? 即: var myapp = angular.module('offersApp', []) .config(['$rootScope', function($rootScope) { } 但是,我在哪里加载下划线库? 我只是在我的索引页面上使用ng-app指令和对angu