Tag: angularjs

从AngularJS URL删除片段标识符(#符号)

是否有可能从angular.jsurl中删除#符号? 我仍然希望能够使用浏览器的后退button等,当我改变视图,并将用PARAMS更新url,但我不想#符号。 教程routeProvider声明如下: angular.module('phonecat', []). config(['$routeProvider', function($routeProvider) { $routeProvider. when('/phones', {templateUrl: 'partials/phone-list.html', controller: PhoneListCtrl}). when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}). otherwise({redirectTo: '/phones'}); }]); 我可以编辑这个具有相同的function没有#?

如何使用$ http POST urlencoded表单数据?

我是AngularJS的新手,一开始我想用AngularJS开发一个新的应用程序。 我正在尝试使用我的Angular App中的$http进行AJAX调用到服务器端。 为了发送参数,我尝试了以下内容: $http({ method: "post", url: URL, headers: {'Content-Type': 'application/x-www-form-urlencoded'}, data: $.param({username: $scope.userName, password: $scope.password}) }).success(function(result){ console.log(result); }); 这是工作,但它也使用jQuery $.param 。 为了消除对jQuery的依赖,我试着: data: {username: $scope.userName, password: $scope.password} 但这似乎失败了。 然后我尝试了params : params: {username: $scope.userName, password: $scope.password} 但这似乎也失败了。 然后我试着JSON.stringify : data: JSON.stringify({username: $scope.userName, password: $scope.password}) 我发现了这些可能的答案,但没有成功。 我做错了什么? 我相信,AngularJS会提供这个function,但是如何?

AngularJS:我怎样才能在控制器之间传递variables?

我有两个angular控制器: function Ctrl1($scope) { $scope.prop1 = "First"; } function Ctrl2($scope) { $scope.prop2 = "Second"; $scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do ideally } 我不能在Ctrl2使用Ctrl2因为它是未定义的。 但是,如果我试图通过它像这样… function Ctrl2($scope, Ctrl1) { $scope.prop2 = "Second"; $scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do ideally } 我得到一个错误。 有谁知道如何做到这一点? […]

如何将数据作为表单数据而不是请求有效载荷发布?

在下面的代码中,AngularJS $http方法调用URL,并将xsrf对象作为“Request Payload”提交(如Chromedebugging器networking选项卡中所述)。 jQuery $.ajax方法执行相同的调用,但将xsrf作为“表单数据”提交。 我如何使AngularJS提交xsrf作为表单数据而不是请求有效载荷? var url = 'http://somewhere.com/'; var xsrf = {fkey: 'xsrf key'}; $http({ method: 'POST', url: url, data: xsrf }).success(function () {}); $.ajax({ type: 'POST', url: url, data: xsrf, dataType: 'json', success: function() {} });

一个控制器可以通话吗?

一个控制器可以使用另一个控制器吗? 例如: 这个HTML文档只是在messageCtrl.js文件中打印由MessageCtrl控制器传递的MessageCtrl 。 <html xmlns:ng="http://angularjs.org/"> <head> <meta charset="utf-8" /> <title>Inter Controller Communication</title> </head> <body> <div ng:controller="MessageCtrl"> <p>{{message}}</p> </div> <!– Angular Scripts –> <script src="http://code.angularjs.org/angular-0.9.19.js" ng:autobind></script> <script src="js/messageCtrl.js" type="text/javascript"></script> </body> </html> 控制器文件包含以下代码: function MessageCtrl() { this.message = function() { return "The current date is: " + new Date().toString(); }; } 哪个只是打印当前的date; 如果我要添加另一个控制器, DateCtrl将date以特定的格式交还给MessageCtrl ,那么怎么做呢? DI框架似乎与XmlHttpRequests和访问服务有关。

如何把重点放在input字段?

在AngularJS中,关注input字段的“angular度方式”是什么? 更具体的要求: 当一个模态被打开时,把焦点设置在这个模态内的一个预定义的<input> 。 每次<input>变得可见(例如通过点击某个button),将焦点放在它上面。 我试图用autofocus 来实现第一个要求 ,但是这只在第一次打开Modal时才有效,并且只在某些浏览器中(例如在Firefox中不起作用)。 任何帮助将不胜感激。

控制器不是一个函数,没有定义,而全球定义控制器

我正在写一个使用angularjs的示例应用程序。 我在Chrome浏览器中遇到下面提到的错误。 错误是 错误:[ng:areq] http://errors.angularjs.org/1.3.0-beta.17/ng/areq?p0=ContactController&p1=not%20a%20function%2C%20got%20undefined 呈现为 参数'ContactController'不是一个函数,没有定义 码 <!DOCTYPE html> <html ng-app> <head> <script src="../angular.min.js"></script> <script type="text/javascript"> function ContactController($scope) { $scope.contacts = ["abcd@gmail.com", "abcd@yahoo.co.in"]; $scope.add = function() { $scope.contacts.push($scope.newcontact); $scope.newcontact = ""; }; } </script> </head> <body> <h1> modules sample </h1> <div ng-controller="ContactController"> Email:<input type="text" ng-model="newcontact"> <button ng-click="add()">Add</button> <h2> Contacts </h2> <ul> <li ng-repeat="contact in […]

使用AngularJS上传文件

这是我的HTML表单: <form name="myForm" ng-submit=""> <input ng-model='file' type="file"/> <input type="submit" value='Submit'/> </form> 我想从本地机器上传图片,并想读取上传文件的内容。 所有这一切,我想用AngularJS做。 当我尝试打印$scope.file的值时,它是未定义的。

为什么angular度的$ http成功/错误方法不推荐使用? 从v1.6中删除?

angular度文档有$http success和error方法的弃用声明。 这个抽象是从图书馆中删除的有一个特定的原因吗?

AngularJS:调用$ scope时,防止错误$ digest正在进行中$ apply()

我发现我需要手动更新我的页面到我的范围越来越多,因为build立一个angular度的应用程序。 我知道这样做的唯一方法是从我的控制器和指令的范围调用$apply() 。 这个问题是它一直向控制台抛出一个错误: 错误:$摘要已在进行中 有谁知道如何避免这个错误,或以不同的方式实现相同的事情?