Tag: angularjs scope

$ scope。当我从指令更新时,$ watch不会触发

我有以下代码片段: HTML: <div data-filedrop data-ng-model="file"></div> 控制器: $scope.$watch('file', function(newVal) { if (newVal) { alert("File",newVal); }, false); } 指示: angular.module('app').directive('filedrop', function () { return { restrict: 'A', templateUrl: './directives/filedrop.html', replace: true, scope: { ngModel: '=ngModel' }, link: function (scope, element) { var dropzone = element[0]; dropzone.ondragover = function () { this.className = 'hover'; return false; }; dropzone.ondragend […]

angularJS控制器第一次不加载

在视图里面,我宣称: <div ng-controller="LoginController"> <div ng-if="authenticated=='no'"> <a href="/signin">Sign In</a> </div> <div ng-if="authenticated=='yes'"> <a href="/logout">Logout</a> </div> </div> 请注意,在上面的代码行之前正确调用包含控制器的angular度文件。 在我的控制器里面,我试图从一个节点API加载数据,用$http get请求,并将其结果设置为如下所示的范围: var indexModule = angular.module ('indexModule', []); indexModule.controller('LoginController',['$scope', '$http', function($scope, $http){ $http.get('/api/data') .success(function(data){ $scope.authenticated = data.authenticated; }) .error(function(){ alert('Error occured'); }); 这只在几个页面刷新后才起作用。 有什么我做错了吗? UPDATE 这里是node.js路由: app.get('/api/data', function (req,res) { // this is called by the controller to populate […]

如何在指令中使用/同步控制器的数据?

经过一番调查,我无法find我的问题的答案。 我有一个从数据库中获取数据的控制器,我把一些数据放在一个表中(在其他地方使用)。 Employees.getEmployees() // A service that return $http.get … .success(function(data) { $scope.employees = data; }); $scope.salesData = []; angular.forEach($scope.employees,function(employees){ $scope.salesData.push(employees.totalSales); }); 我想在指令中使用这个$ scope.salesData,用D3JS创build一个图表。 angular.module('dirDonut', []) .directive("linearChart", function($window) { return{ restrict: "EA", link: function(scope, el, attrs){ // retrieve datas from the Controller var data=scope[attrs.chartData]; // Here the code creates the chart … } }; }); […]

作用域不在$ apply上更新使用

我有一块$ scope文本应该dynamic更新。 <span ng-bind="user.balance"></span> 按下button后,新的平衡值被接收,并显示在这里。 $http.post('/transaction/send', transaction).success(function(sender) { console.log("http response"); $scope.user = sender; console.log($scope.user.balance); $timeout(function() {$scope.$apply(); console.log("apply used");}, 1000); }); 在控制台日志中,任何东西都会被正确接收和显示,但是它仍然不会在视图中更新范围。 我究竟做错了什么? 我正在使用$超时摆脱“$摘要已被使用”

meteorangular度和请求 – 如何绑定?

我试图完成我的脚本的最后一个阶段,这是显示响应。 我有一个meteor的方法,通过基本authentication,从Zendesk的API请求一个对象。 此方法在我的客户端部分中由Meteor.call()调用。 我可以logging响应,但无法将其绑定和显示。 这是我的js: if (Meteor.isClient) { // This code only runs on the client angular.module('equationKPIs', ['angular-meteor']); angular.module('equationKPIs').controller('EquationKPICtrl', ['$scope', function ($scope) { Meteor.call("zendeskUnsolvedTickets", function (error, results) { var json = JSON.parse(results); $scope.metrics = [{ 'name': 'Unsolved Tickets', 'value': json.view_count.pretty }]; console.log($scope.metrics); }); }]); } if (Meteor.isServer) { Meteor.methods({ zendeskUnsolvedTickets: function () { var request […]

Angularjs socket.io服务

您好我build立一个angularjs服务,将通过socket.io使用websockets与后端(node.js)沟通。 我在网上find了一小段代码,但是我不太明白它是如何工作的。 特别是在“var args = arguments”下面的行上。 帮帮我? angularjs_service.js app.factory('socket', function ($rootScope) { var socket = io.connect(); return { on: function (eventName, callback) { socket.on(eventName, function () { var args = arguments; $rootScope.$apply(function () { callback.apply(socket, args); }); }); }, emit: function (eventName, data, callback) { socket.emit(eventName, data, function () { var args = arguments; $rootScope.$apply(function […]

如何使控制器等待服务返回一个值,以及如何访问控制器中返回的值?

我是angularjs的新手 。 我在访问从其控制器中的angularjs服务返回的值时遇到问题。 以下是控制器中的代码: 'use strict'; app.controller('AdminTaskCtrl', function ($scope, Search) { $scope.buildEnquiry = function (collegeId, ) { Search.getIdByEmail(collegeId).then ( function ( result ) { $scope.uId = result; console.log($scope.uId); }); }; });//controller ends here search服务中的代码如下所示: 'use strict'; app.factory('Search',function ($firebase, FIREBASE_URL, $rootScope) { var simpleuser = ""; getIdByEmail: function(counsellorEmail) { var collegeuserArray = ($firebase(new Firebase(FIREBASE_URL+"abc/def/")).$asArray()); collegeuserArray.$loaded(function(collegeuserArray) { […]