草庐IT

angularjs-module

全部标签

javascript - AngularJS - 我的部分 Controller

我有一个模板,它在我的DOM中追加了很多次。contentdoesnotmatter因此Controller被多次验证。这是一个问题,因为如果我在Controller中放置一个观察者theController=function($scope){$scope.$on('myVar',function(){//runonetimeforeachtimethetemplateisrepeated})}关于如何避免这种情况的任何想法?提前致谢。更新好的,我会尽量说得更清楚。也许我有一个表单,它是根据异步请求的响应动态构建的。Controller是这样的:functionformControll

javascript - 在模型更改时触发自定义 AngularJS 表单验证

我有一个自定义验证指令,用于确保两个日期在有效范围内。当用户更改值时该指令工作正常,但是当我通过AJAX加载新的lineItem模型时它不会触发。问题是用户可以在表单中输入无效日期并触发错误,然后加载另一个lineItem。此时,即使表单中的数据有效,表单上也会出现错误消息。如果我尝试使用Angular的内置验证(如required)做同样的事情,验证会触发并适当消失。那么,我需要做什么才能使我的验证触发方式与Angular的触发方式相同?(注意:我在表单属性和Angularv1.1.5上使用novalidate)指令ngApp.directive("validateBefore",f

javascript - AngularJS 过滤器将 html 作为字符串返回

我已经创建了一个AngularJS过滤器来自动从数据中找到的地址创建可点击的链接。过滤器:app.filter('parseUrl',function(){var//URLsstartingwithhttp://,https://,orftp://replacePattern1=/(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim,//URLsstartingwith"www."(without//beforeit,orit'dre-linktheonesdoneabove).replaceP

javascript - 在 AngularJS 应用程序中使用 select2 插件

我在我的AngularJS应用程序中使用select2插件来显示一些实体(标签)的列表。这是我的模板部分:select.ddlTags(ui-select2="select2Options",multiple,ng-model="link.tags")option(ng-repeat="tagintags",value="{{tag.id}}"){{tag.name}}这是我的范围代码的一部分:$scope.select2Options={formatNoMatches:function(term){varmessage='Добавитьтэг"'+term+'"'console.l

javascript - 将 $http 拦截器创建为独立模块时 Angular 中的依赖项错误

这是一个工作示例,说明我如何设置一个拦截器,该拦截器将身份验证token附加到每个请求(这或多或少是来自https://docs.angularjs.org/api/ng/service/$http的示例)angular.module("app",[]).config(function($httpProvider){$httpProvider.interceptors.push("authInterceptor");}).factory("authInterceptor",function($q){return{//interceptorconfigurationhere}})我的co

javascript - 在 Angularjs 中使用多个指令

我遇到需要访问多个指令Controller方法的情况。我可以像这样使用require从父指令访问方法:require:"^parentDirective"但我还需要访问单独指令(不是父指令)中的方法,文档对useanarrayofstrings说像这样:require:["^parentDirective","directiveTwo"]但这样做会导致错误,尽管这两个指令都已编译到DOM中。我是不是漏掉了什么?这是我的指令:angular.module('testModule',['parentModule'],function(){}).directive('testDirectiv

javascript - AngularJS 错误 :Module 'ngResource' is not available! 您拼错了模块名称或忘记加载它

我正在尝试从angularjs进行服务调用。我下载了angularseedproject.并且在view1.js里面写了下面的代码来调用服务:'usestrict';angular.module('myApp.view1',['ngRoute','ngResource']).config(['$routeProvider',function($routeProvider){$routeProvider.when('/view1',{templateUrl:'view1/view1.html',controller:'View1Ctrl'});}]).factory('Entry',['

javascript - TypeError : value. push is not a function with Angularjs $resource 查询

我从服务器返回一个对象数组:[{id:1,name:"name"},{id:2,name:"name2"}]现在我使用angular-resource$query来获取数据,因为它需要一个数组。收到数据后出现此错误:TypeError:value.pushisnotafunction我从server=给出的响应有问题吗?错误来源://jshint+W018if(action.isArray){value.length=0;forEach(data,function(item){if(typeofitem==="object"){value.push(newResource(item))

javascript - Jest : cannot find module required inside module to be tested (relative path)

我有这个组件:importReactfrom'react';importVideoTagfrom'./VideoTag';importJWPlayerfrom'./JWPlayer';classVideoWrapperextendsReact.Component{//...componentcode}基于某些逻辑在内部呈现另一个组件(VideoTag或JWPlayer)但是当我尝试在一个Jest文件中测试它时我得到错误:找不到模块'./VideoTag'这三个组件在同一个目录中,这就是为什么当我转译它并在浏览器中看到它在运行时它实际上有效但看起来Jest在解析这些相对路径时遇到问题,这

javascript - 访问 AngularJs 指令 Controller

我在尝试使用jasmine和karmatestrunner进行单元测试的指令访问我的Controller时遇到了一些问题。该指令如下所示:指令angular.module('Common.accountSearch',['ngRoute']).directive('accountSearch',[function(){return{controllerAs:'ctrl',controller:function($scope,$element,$routeParams,$http){this.setAccount=function(){varresponse={AccountId:$sc