小编Bye*_*Bye的帖子

如何从AngularJS中的范围中删除项目?

简单的待办事项列表,但每个项目的列表页面上都有一个删除按钮:

在此输入图像描述

相关模板HTML:

<tr ng-repeat="person in persons">
  <td>{{person.name}} - # {{person.id}}</td>
  <td>{{person.description}}</td>
  <td nowrap=nowrap>
    <a href="#!/edit"><i class="icon-edit"></i></a>
    <button ng-click="delete(person)"><i class="icon-minus-sign"></i></button>
  </td>
</tr>
Run Code Online (Sandbox Code Playgroud)

相关控制器方法:

$scope.delete = function (person) {
  API.DeletePerson({ id: person.id }, function (success) {
    // I need some code here to pull the person from my scope.
  });
};
Run Code Online (Sandbox Code Playgroud)

我试着$scope.persons.pull(person)$scope.persons.remove(person).

虽然数据库已成功删除,但我无法从作用域中提取此项目,并且我不想对客户端已有的数据进行服务器方法调用,我只是想从范围中删除这一个人.

有任何想法吗?

html javascript angularjs

153
推荐指数
4
解决办法
25万
查看次数

如果选中复选框则需要输入值

我有一系列行,每个行一个复选框.每行有几个输入.我已经进行了验证,要求检查所有行中至少有一个复选框.但是,我迄今无法要求输入只有一个值才能选中复选框.

在此输入图像描述

HTML:

<div style="width: 100%;">
<checkboxgroup-Wheelbase min-required="1">          
    <table style="width: 100%">                                
        <tr>
            <td>
                <table style="width: 97%;">
                    <tr>
                        <th style="width: 220px;" class="wheelbaseHeaderCell">Wheelbase<br /><span style="font-weight: 400;">(choose min of 1)</span></th>
                        <th class="wheelbaseHeaderCell">Payload<br />[ pounds ]</th>
                        <th class="wheelbaseHeaderCell">Length<br />[ inches ]</th>
                        <th class="wheelbaseHeaderCell">Height<br />[ inches ]</th>
                        <th class="wheelbaseHeaderCell">Weight<br />[ pounds ]</th>
                        <th class="wheelbaseHeaderCell">Turn Radius<br />[ feet ]</th>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td style="height: 5px;"></td>
        </tr>
        <tr>
            <td>
                <div style="height: 170px; overflow: auto;">
                    <table style="width: 100%;">
                        <tr class="rowGroup" ng-repeat="wheelbase in wheelbases" data-rowParent="wheelbase[wheelbase.Id]">
                            <td class="wheelbaseCell" style="padding-left: …
Run Code Online (Sandbox Code Playgroud)

angularjs

16
推荐指数
1
解决办法
1万
查看次数

错误:不可分配的模型表达式:undefined(指令:childOne)

作为后续仍然关于这个plunker:

plunker

如果我在选择Child 1中的项目时在Chrome中查看控制台,则会收到以下错误:

错误:不可分配的模型表达式:undefined(指令:childOne)

我完全感到困惑,因为指令元素是一个元素,而不是一个属性,并在指令本身中指定为这样.

angularjs

14
推荐指数
1
解决办法
2万
查看次数

AngularJs,DropZone.Js,MVC4 - 拖放,预览和预览上传的图像

HTML:

<script src="~/Scripts/jquery-1.9.1.js"></script>
<script src="~/Scripts/DropZone-2.0.1.js"></script>
<script src="~/Scripts/angular.js"></script>
<script src="~/App_Angular/app.js"></script>

<div ng-app ="myApp" ng-controller ="ProductsCtrl">
<input ng-model="product.Name"/>
<input ng-model="product.PhotoName" id="result" />
<form id="dropzone"  class="fade well">Drop files here</form>
<input type="button" value="Upload Files" ng-click="save(product)" />
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

$("#dropzone").dropzone({
    url: 'Home/UploadFiles',
    paramName: "files", // The name that will be used to transfer the file
    maxFilesize: 102, // MB
    enqueueForUpload: false,
    accept: function (file, done) {
        angular.element(document.getElementById('result')).scope()
            .$apply(function (scope) {
                scope.product.PhotoName = $('#result').val();
            });

        return done();
    }
});

function uploadClicked() {
    var dz = Dropzone.forElement("#dropzone");
    for …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc-4 angularjs

7
推荐指数
1
解决办法
1万
查看次数

AngularJS - '请从列表中选择一个项目" - 来自哪里?

我很困惑.在我的表单中,通过具有以下属性的提交按钮:

NG-禁用= "templateForm $无效"

我的选择是必需的

我收到一个不受欢迎的弹出窗口,询问"请从列表中选择一个项目".

我搜索了整个应用程序,因为我确信我没有远程引用.

有谁知道它来自何处以及如何停止/覆盖/禁用它?

谢谢.

有了Galdo的帮助:

  <form id="addForm" ng-submit="doSomething()" name="templateForm" novalidate>
Run Code Online (Sandbox Code Playgroud)

诀窍.

angularjs

4
推荐指数
1
解决办法
3361
查看次数

为什么在图像和css文件之后查询字符串?

我在各个站点上看到了一个查询字符串,后面是图像和css文件的数字.当我查看源代码(通过Chrome Developer)时,缓存的css文件和图像的名称中没有查询字符串中的数字.当我刷新页面时,我也在网站上看到了查询字符串中的数字发生了变化.

例如:

myimage.jpg?NUM = 12345

myStyles.css?NUM = 82943

刷新后:

myimage.jpg?NUM = 67948

myStyles.css?NUM = 62972

任何人都可以向我解释这些查询字符串的目的可能是什么?

php asp.net html5 asp.net-mvc-3

3
推荐指数
1
解决办法
1261
查看次数

AngularJS,MVC4,Web API,Json反序列化$ ref

通过HttpResponseMessage MVC4成功发送一个AngularJs控制器$范围的GetAllFolders().

集合中的文件夹除了其他内容之外还与Photo类相关联.

文件夹可以是其他文件夹的文件夹(自引用).

从MVC4端调试显示一切都很好,返回了正确的详细信息.

但是通过Angular/Json,某些属性是$ ref tag并且无法看到,例如:

在此输入图像描述

我不太关心在FkPhotoId上创建一个方法调用,并且当我知道它已经在第一个响应中发送时,在服务器上找到了图像名称.

有任何想法吗?

更新:解决方案

此代码已添加到global.asax中:(请确保在start方法中引用它)

    public static void ConfigureApi(HttpConfiguration config)
    {
        var json = config.Formatters.JsonFormatter;
        config.Formatters.Remove(config.Formatters.XmlFormatter);
        config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; 
    }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

json asp.net-mvc-4 asp.net-web-api angularjs

2
推荐指数
1
解决办法
2651
查看次数