Tag: angularjs directive

$ 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 […]

如何在每一个angular度创build星形图标?

我正在尝试在每一行中制作星形图标。我正在dynamic生成行,但是我能够生成行,但是我的星形图标在顶部行的顶部可见。为什么..我需要在每一行中显示开始图标。 http://plnkr.co/edit/mBoAX5xaVTYvdrRuafEw?p=preview <table ng-table class="table"> <tr ng-repeat="guitar in guitarVariable" style="border: 5px solid #000000; background: pink" > <span class="glyphicon glyphicon-star"></span> <td data-title="'Name'">{{guitar.color}} </td> <td data-title="'class'">{{guitar.value}}</td> </tr> </table>

validation问题使用angularjs(红色边框在Firefox上显示)?

我从对象做了一个简单的表单..现在我validation该表单。我在validation时遇到了一些问题。请在firefox上检查这个。 当我写入需要的时候,我的字段变成了红色(在input字段上是红色的边框),运行应用程序后显示“请input有效的电子邮件”,当用户将一个字段移动到另一个字段时,该字段变为红色,我需要显示两条消息“请input电子邮件”与“请input有效的电子邮件”我怎么能做到这一点? 我学习了很多的教程,但我应用这个东西$脏,$原始,但没有为我工作..我学习从那里validation.. http://scotch.io/tutorials/javascript/angularjs-form-validation <ul ng-repeat="input in inputs"> <li><span>{{input.name}} : </span> <div ng-switch="input.type" ng-form="myfrm"> <div ng-switch-when="text"> <input type="text" ng-model="outputs[input.name]"/> </div> <div ng-switch-when="email" class="form-group" > <input type="email" ng-model="outputs[input.name]" name="input" ng-required="input.required"> <P ng-show="myfrm.input.$invalid && !myform.input.$pristine">Please enter a valid email</P> </div> <div ng-switch-when="number"> <input type="number" ng-model="outputs[input.name]" ng-required="input.required" name="input"/> <P ng-if="myfrm.input.$invalid">Please enter a valid number</P> </div> <div ng-switch-when="url"> <input […]

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

经过一番调查,我无法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 … } }; }); […]

angularjs指令不起作用(node.js和angularjs newbee)

我正在学习AngularJS和Node.js. 我试图build立一个小型网站(“你好网站”),但我有一个angularjs指令(我猜)的问题。 这是我的项目结构 根 + angularFiles —— angularMenu.js +模板 —— menu.html – index.html – servidor.js 正如你所看到的,没有什么特别的…文件的代码: servidor.js (web server) var port=9000; //importamos librerias etc… var express= require('express'); var app=express(); app.use(express.static(__dirname+'/')); //rutas para las peticiones app.get('/',function(req,res) { res.sendFile(__dirname+'/index.html'); console.log("index"); }); app.listen(port); console.log("servidor lanzado y escuchando en puerto "+port); Web服务器工作 index.html <!DOCTYPE html> <html lang='es'> <head> <title>Colonias […]

在angular度种子克隆的“npm start”命令中出错

当我从github克隆angular种子并运行节点服务器时,出现以下错误。 我已经将angular种子克隆到现有的项目目录。 我不确定发生了什么问题。 但是我得到了下面的错误。 请帮助 $ npm start > StickyTodos@0.0.0 prestart C:\projects\StickyTodos > npm install > StickyTodos@0.0.0 postinstall C:\projects\StickyTodos > bower install > StickyTodos@0.0.0 start C:\projects\StickyTodos > http-server -a localhost -p 8000 -c-1 events.js:141 throw er; // Unhandled 'error' event ^ Error: listen EADDRINUSE 127.0.0.1:8000 at Object.exports._errnoException (util.js:860:11) at exports._exceptionWithHostPort (util.js:883:20) at Server._listen2 (net.js:1234:14) at […]

将markdown整合到angularjs中?

我已经开始使用AngularJS + NodeJS编写一个简单的应用程序来了解更多关于堆栈的信息,看起来markdown工作起来有点棘手,但是没有得到很好的支持。 我来自一个ruby背景,我使用的是redcarpet降价库,这是非常标准和直接。 我遇到了angular-markdown-directive : 优点 设置简单 使用ngSanitize清理用户提交的降价。 这个图书馆是由Angular官方团队支持的。 缺点 它在引擎盖下使用showdown ,似乎已经死了一段时间,但小的进展似乎正在与新的维护者正在接近。 然而,它有不less突出的bug,2013年和2014年的两个特别bug报告令人担忧: (1)下划线显然被解释为斜体(将创build格式不正确的链接): https://github.com/showdownjs/showdown/issues/96 : https://github.com/showdownjs/showdown/issues/96 (2)安全问题,使XSS仍未修补: https://github.com/showdownjs/showdown/issues/57 : https://github.com/showdownjs/showdown/issues/57 我不确定(2)是否会成为我的情况,因为ngSanitize可能有帮助。 还有另一个名为markdown-it库,但是这个库在Nodejs中处理Markdown而不是Angular。 但是他们的例子并没有提到最好的安全实践。 – 有没有关于如何安全地将Markdown安全地集成到Node / Angular应用程序中的完整示例? angular-markdown-directive似乎是一个不错的select,但有一些令人痛苦的问题,而其他大多数markdown库都是死亡/死亡,或者它们在生产环境中的安全性。

为什么元素不是dynamic添加在angular

我正在尝试使用ng-repeatdynamic添加数据。 我不知道为什么不加。 我input数据中dynamic添加的“名称”,但不显示在用户界面中。 这里是一个演示 app.controller("studentcntr", ['$scope', function(scope) { scope.studentDetail = []; var student = { name: '' }; scope.addStudent = function() { bootbox.prompt("Enter Name!", function(res){ if (res == null) { } else { student.name = res; scope.studentDetail.push(student); } }); }; }])

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 […]

如何在Morris JSgraphics的Angular JS中创build一个指令

我正尝试通过创build一个Angular JS指令来创build一个使用Morris JS的图。 我的指令代码是: Reporting.directive('morrisLine', function(){ return { restrict: 'EA', template: '<div id="call-chart">test2</div>', scope: { data: '=', //list of data object to use for graph xkey: '=', ykey: '=' }, link: function(scope,element,attrs){ new Morris.Line({ element: element, data: [ { year: '2008', value: 20 }, { year: '2009', value: 10 }, { year: '2010', value: 5 […]