草庐IT

scoped_model

全部标签

javascript - AngularJS 1.4 指令 : scope, 两种方式绑定(bind)和 bindToController

Update:Itmusthavebeensomethingstupidinanotherpartofthecode.Itworksnow,sothebindToControllersyntaxisfine.我们正在使用AngularJS1.4,它引入了一个newwaytousebindToController在指令中。经过相当多的阅读(也许还没有完全理解),我们这样定义了我们的指令:.directive('mdAddress',functionmdAddress(){vardirective={restrict:'EA',scope:{},bindToController:{addr

javascript - Angular JS : get ng-model on ng-change

我有以下HTML这是由以下带有国家列表的对象提供的$scope.countries=[{name:Afeganistão,country:AF},{name:ÁfricadoSul,country:ZA},name:Albânia,country:AL},{name:Alemanha,country:DE},{name:Andorra,country:AD}...];当我更改下拉列表值时,我希望我的模型($scope.country)在filterByCountry函数内得到更新,但事实并非如此。我在这里缺少什么? 最佳答案 ng-

javascript - ng-model 防止选中 ="checked"默认选择单选按钮

当我使用checked="checked"时,ng-model会阻止单选按钮被默认选中。有谁知道是什么原因造成的? 最佳答案 您应该使用Angular附带的ngChecked指令。文档:http://docs.angularjs.org/api/ng.directive:ngChecked 关于javascript-ng-model防止选中="checked"默认选择单选按钮,我们在StackOverflow上找到一个类似的问题: https://stacko

javascript - 如何将使用 $scope 的函数包含/注入(inject)到 angularjs 的 Controller 中?

我正在尝试将工厂中保存的函数库包含到Controller中。类似于这样的问题:Creatingcommoncontrollerfunctions我的主Controller是这样的:recipeApp.controller('recipeController',function($scope,groceryInterface,...){$scope.groceryList=[];//...etc.../*tryingtoretrievethefunctionshere*/$scope.groceryFunc=groceryInterface;//wouldcallng-click="gr

javascript - 为什么我的 ng-model 变量在 Controller 中未定义?

我在angularjs项目中遇到$scope问题。例如,当我在输入字段上使用ng-model="modelExample"时,我无法使用$scope.modelExample在我的js中访问它。有没有其他人遇到过类似的问题?这很奇怪,调用了一个函数但ng-model没有绑定(bind)。请参阅下面的代码,当我提交表单时调用函数refreshResults()但$scope.search返回未定义。angular.module('starter',['ionic','starter.controllers','starter.filters','akoenig.deckgrid',"an

javascript - 在 AngularJS 中设置动态 ng-model 名称

还有类似的问题here和here,虽然我的用例有点不同。我有一个名为uniqueLists的对象,它看起来像这样:$scope.uniqueLists-{name:['string1','string2','string3'//Lotsofstrings],Category:['string1','string2','string3'//Lotsofstrings],designer:['string1','string2','string3'//Lotsofstrings]}我正在尝试从这个列表中构建一个搜索功能。目前,我可以像这样在页面上的复选框中显示所有列表项(以下代码使用Jad

javascript - AngularJS 如何在 2 个或更多 Controller 中解析对 $scope 变量的调用?

Here,作者提到the$scopeobjectusedbythetwocontrollersarenotthesame$scopeobject同样的片段:现在考虑对上面的代码做一点修改。{{data.theVar}}{{data.common}}{{data.theVar}}{{data.common}}{{temp}}{{newTemp}}varmodule=angular.module("myapp",[]);varmyController1=module.controller("myController1",function($scope){$scope.data={theVa

JavaScript 模块模式 : How do private methods access module's scope?

在实现模块模式时,私有(private)函数如何访问模块的私有(private)属性?我还没有看到开发人员这样做的任何例子。有什么理由不这样做吗?varmodule=(function(){//privatepropertyvarnumber=0;//privatemethod_privateIncrement=function(){//howdoIaccessprivatepropertieshere?number++;};//publicapireturn{//OKgetNumber:function(){returnnumber;},//OKincrNumber:function

javascript - $scope.$on 在 $rootScope.$broadcast 之后不触发

这可能是重复出现的问题,但我找到的针对此问题的解决方法在我的情况下不起作用,这就是我发布问题的原因。我已关注服务:appRoot.service('MyService',function($rootScope){varMessenger={Temp:"",TempId:"",tempMethod:function(Id){TempId=Id;$rootScope.$broadcast('FirstCtrlMethod');}};returnMessenger;});在第二个Controller中:appRoot.controller('SecondCtrl',function($sco

javascript - 什么时候使用 $scope.$apply() 是安全的?

我想标题已经很清楚我要问什么了。我创建了这个fiddle:http://jsfiddle.net/Sourabh_/HB7LU/13142/在fiddle中,我试图复制一个async场景。这只是一个示例,但在AJAX调用中,如果我不使用$scope.$apply(),则列表不会更新。我想知道每次进行AJAX调用以更新列表时使用$scope.$apply()是否安全,或者是否有其他一些我可以利用的机制?我为复制场景而编写的代码(与fiddle中的相同):HTML{{item.name}}ChangeJSvarmyApp=angular.module('myApp',[]);functio