关于使用AngularJS获取地理位置坐标和angular获取ip地址的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于angularjs–使用angular-translate获取当前语言
关于使用AngularJS获取地理位置坐标和angular获取ip地址的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于angularjs – 使用angular-translate获取当前语言、angularjs – 使用Angular.js从Web服务获取数据、angularjs – 可以在AngulrJS 1.3.0项目中使用angular / di.js吗?、angularjs – 如何使用angular-file-upload获取图像尺寸等相关知识的信息别忘了在本站进行查找喔。
本文目录一览:- 使用AngularJS获取地理位置坐标(angular获取ip地址)
- angularjs – 使用angular-translate获取当前语言
- angularjs – 使用Angular.js从Web服务获取数据
- angularjs – 可以在AngulrJS 1.3.0项目中使用angular / di.js吗?
- angularjs – 如何使用angular-file-upload获取图像尺寸
使用AngularJS获取地理位置坐标(angular获取ip地址)
这是控制器中的功能,我在其中分配纬度和经度的值并将它们打印到浏览器控制台.调用nearme()函数,
var mysrclat= 0; var mysrclong = 0; $scope.nearme = function($scope) { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function (position) { mysrclat = position.coords.latitude; mysrclong = position.coords.longitude; }); console.log(mysrclat); console.log(mysrclong); } }
问题是,第一次,坐标打印为0,0.然后,打印出正确的坐标值.为什么第一次打印0,0作为坐标?
解决方法
function (position) { mysrclat = position.coords.latitude; mysrclong = position.coords.longitude; console.log(mysrclat); console.log(mysrclong); });
http://jsfiddle.net/glebv/axrw7g90/18/
angularjs – 使用angular-translate获取当前语言
在$ translate服务中找不到任何内容。
请参阅文档链接中的此演示:
http://jsfiddle.net/PascalPrecht/eUGWJ/7/
angularjs – 使用Angular.js从Web服务获取数据
数据来自Web服务正确,但我不能在控制器内使用它.
这是为什么?
角度代码:
var booksJson; var app = angular.module('booksInventoryApp',[]); // get data from the WS app.run(function ($http) { $http.get("https://SOME_API_PATH").success(function (data) { booksJson = data; console.log(data); //Working }); }); app.controller('booksCtrl',function ($scope) { $scope.data = booksJson; console.log($scope.data); //NOT WORKING });
HTML:
<section ng-controller="booksCtrl"> <h2 ng-repeat="book in data">{{book.name}}</h2> </section>
解决方法
此外,Web服务返回的对象不是数组.所以你的ng-repeat应该是这样的:在data.books中预订
这是一个工作示例:
var app = angular.module('booksInventoryApp',[]); app.controller('booksCtrl',function($scope,$http) { $http.get("https://whispering-woodland-9020.herokuapp.com/getAllBooks") .then(function(response) { $scope.data = response.data; }); });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <article ng-app="booksInventoryApp"> <section ng-controller="booksCtrl"> <h2 ng-repeat="book in data.books">{{book.name}}</h2> </section> </article>
angularjs – 可以在AngulrJS 1.3.0项目中使用angular / di.js吗?
问题是,我不清楚我是否可以使用它.在github项目示例中,似乎没有使用AngularJS v1的例子.
我在Backbone项目中发现了一个例子:http://teropa.info/blog/2014/03/18/using-angular-2-0-dependency-injection-in-a-backbone-app.html,我发现在AngularJS v1项目中使用ES6的一个例子:https://github.com/mvolkmann/todo-es6/,但是我在Angular v1项目中找不到使用新的DI的例子.
我很困惑.任何指针?
一个小例子和一个可能的开始:
var falafel = require('falafel'); var traceur = require('traceur'); var src = '@Inject(MyService,MyOtherService)' + 'class Thing{' + ' constructor(service,otherservice){' + ' }' + '}'; src = traceur.compile(src,{ annotations: true }); //console.log(src); function tryGetPath(obj,path) { path.split('.').forEach(function(key) { obj = obj && obj[key]; }); return obj; } var output = falafel(src,function(node) { //find `Object.defineProperty for 'annotations'` if (node.type === 'CallExpression' && tryGetPath(node,'arguments.1.value') === 'annotations') { var injectable = tryGetPath(node,'arguments.0.name'); var $inject = (tryGetPath(node,'arguments.2.properties.0.value.body.body.0.argument.elements') || []) .filter(function(a){return a.callee.name === 'Inject'}) .reduce(function(p,c){ p.push.apply(p,c.arguments); return p;},[]) .map(function(a){return "'"+a.name+"'";}); node.update(injectable + '.$inject = [' + $inject.toString() + '];'); } }); console.log(output);
也许您甚至可以使用某些属性(例如@NgController等)将其注册到您的模块上作为控制器.
angularjs – 如何使用angular-file-upload获取图像尺寸
我需要在那里添加一个步骤来测试图像的尺寸,我目前只能通过jQuery / javascript来做.
只是想知道在上传之前是否有一种“有角度”的方式来检查图像的尺寸?
$scope.uploadImage = function($files) { $scope.selectedFiles = []; $scope.progress = []; if ($scope.upload && $scope.upload.length > 0) { for (var i = 0; i < $scope.upload.length; i++) { if ($scope.upload[i] !== null) { $scope.upload[i].abort(); } } } $scope.upload = []; $scope.uploadResult = []; $scope.selectedFiles = $files; $scope.dataUrls = []; for ( var j = 0; j < $files.length; j++) { var $file = $files[j]; if (/*$scope.fileReaderSupported && */$file.type.indexOf('image') > -1) { var fileReader = new FileReader(); fileReader.readAsDataURL($files[j]); var loadFile = function(fileReader,index) { fileReader.onload = function(e) { $timeout(function() { $scope.dataUrls[index] = e.target.result; //------Suggestions?-------// $('#image-upload-landscape').on('load',function(){ console.log($(this).width()); }); //-------------------------// }); }; }(fileReader,j); } $scope.progress[j] = -1; if ($scope.uploadRightAway) { $scope.start(j); } } };
解决方法
var reader = new FileReader(); reader.onload = onLoadFile; reader.readAsDataURL(filtItem._file); function onLoadFile(event) { var img = new Image(); img.src = event.target.result; console.log(img.width,img.height) }
这是从https://github.com/nervgh/angular-file-upload/blob/master/examples/image-preview/directives.js复制的代码段.
我认为这更像是angularjs.但是,您可能需要对其进行修改以满足您的要求.
关于使用AngularJS获取地理位置坐标和angular获取ip地址的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于angularjs – 使用angular-translate获取当前语言、angularjs – 使用Angular.js从Web服务获取数据、angularjs – 可以在AngulrJS 1.3.0项目中使用angular / di.js吗?、angularjs – 如何使用angular-file-upload获取图像尺寸等相关内容,可以在本站寻找。
本文标签: