示例中,根据ng-if指令显示不同任务状态,以及判断任务是否可以操作

<div ng-app="NgifDemoApp" ng-controller="NgifDemoContrl as vm">
<h1>任务列表</h1>
<table class="table">
<thead>
<tr>
<th>任务编号</th>
<th>任务名称</th>
<th>任务状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<!--ng-repeat指令,类似foreach循环-->
<tr ng-repeat="item in vm.taskList">
<td><p>{{ item.Id }}</p></td>
<td><p>{{ item.TaskName }}</p></td>
<td>
<!--此处的效果,也可以通过在TaskModel里面加一个string字符串,返回OwnStatus的字符串结果来完成-->
<p ng-if="item.OwnStatus==0">准备开工</p>
<p ng-if="item.OwnStatus==1">进行中</p>
<p ng-if="item.OwnStatus==2">已经完成</p>
</td>
<td>
<button ng-if="item.OwnStatus==0 || item.OwnStatus==1">更新任务情况</button>
</td>
</tr>
</tbody>
</table>
</div>
<script src="~/Scripts/angular.min.js"></script>
<script>
var app = angular.module('NgifDemoApp', []);
app.controller('NgifDemoContrl', function ($scope, $http) {
var vm = this;
vm.getdata = function () {
$http({
method: 'POST',
url: '/AngularjsStudy/GetNgifData',
data: {}
}).then(function successCallback(data) {
//data有多余属性,data.data才是controller返回的data
vm.taskList = data.data;
}, function errorCallback(response) {
// 请求失败执行代码
});
}
vm.getdata();
});
</script>

Controller

public ActionResult GetNgifData()
{
List<TaskModel> list = new List<TaskModel>();
list.Add(new TaskModel() { Id = 1, TaskName = "任务1", OwnStatus = Status.todo });
list.Add(new TaskModel() { Id = 2, TaskName = "任务2", OwnStatus = Status.done });
list.Add(new TaskModel() { Id = 3, TaskName = "任务3", OwnStatus = Status.doing });
list.Add(new TaskModel() { Id = 4, TaskName = "任务4", OwnStatus = Status.doing });
list.Add(new TaskModel() { Id = 5, TaskName = "任务5", OwnStatus = Status.todo });
return Json(list);
}

Model

public enum Status
{
todo=0,
doing=1,
done=2
}
public class TaskModel
{
public int Id { get; set; }
public Status OwnStatus { get; set; }
public string TaskName { get; set; }
}

AngularJS ng-if使用的更多相关文章

  1. Part 6 AngularJS ng repeat directive

    ng-repeat is similar to foreach loop in C#. Let us understand this with an example. Here is what we ...

  2. part 4 AngularJS ng src directive

  3. Part 15 AngularJS ng init directive

    The ng-init directive allows you to evaluate an expression in the current scope.  In the following e ...

  4. [AngularJS] AngularJS系列(1) 基础篇

    目录 什么是AngularJS? 为什么使用/ng特性 Hello World 内置指令 内置过滤器 模块化开发 一年前开始使用AngularJS(以后简称ng),如今ng已经出2了.虽说2已完全变样 ...

  5. 从angularJS看MVVM

    javascript厚积薄发走势异常迅猛,导致现在各种MV*框架百家争雄,MVVM从MVC演变而来,为javascript注入了全新的活力.我工作的业务不会涉及到angularJS[ng]这么重量级的 ...

  6. angularJS看MVVM

    从angularJS看MVVM   javascript厚积薄发走势异常迅猛,导致现在各种MV*框架百家争雄,MVVM从MVC演变而来,为javascript注入了全新的活力.我工作的业务不会涉及到a ...

  7. js架构设计模式——从angularJS看MVVM

    javascript厚积薄发走势异常迅猛,导致现在各种MV*框架百家争雄,MVVM从MVC演变而来,为javascript注入了全新的活力.我工作的业务不会涉及到 angularJS[ng] 这么重量 ...

  8. .Net Core应用框架Util介绍(一)

    距离上次发文,已经过去了三年半,这几年技术更新节奏异常迅猛,.Net进入了跨平台时代,前端也被革命性的颠覆. 回顾 2015年,正当我还沉迷于JQuery + EasyUi的封装时,突然意识到技术已经 ...

  9. gulp 在 angular 项目中的使用

    gulp 在 angular 项目中的使用 keyword:gulp,angularjs,ng,ngAnnotate,jshint,gulpfile 最后附完整简洁的ng项目gulpfile.js 准 ...

  10. .Net Core应用框架Util介绍(一)转

    回顾 2015年,正当我还沉迷于JQuery + EasyUi的封装时,突然意识到技术已经过时. JQuery在面对更加复杂的UI需求时显得力不从心,EasyUi虽然组件比较完善,但界面风格老旧,响应 ...

随机推荐

  1. SocketChannel API用法

    java.nio.channels 类 SocketChannel java.lang.Object java.nio.channels.spi.AbstractInterruptibleChanne ...

  2. hreadPoolExecutor使用和思考(上)-线程池大小设置与BlockingQueue的三种实现区别

    阅读更多 工作中多处接触到了ThreadPoolExecutor.趁着现在还算空,学习总结一下. 前记: jdk官方文档(javadoc)是学习的最好,最权威的参考. 文章分上中下.上篇中主要介绍Th ...

  3. Java-Maven项目引入UEditor图片上传组件jar包类库的5种方式

    最近,硬是和百度的UEditor组件杠上了.自己的个人官网项目,很容易就搞定了,公司的项目,尼玛,各种问题.项目多了,环境复杂了,解决问题的方法也得不断调整. 项目用Maven管理jar包,用到了UE ...

  4. 【37%】【poj1436】Horizontally Visible Segments

    Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5200   Accepted: 1903 Description There ...

  5. CoreLocation定位

    nCoreLocation   n简介 n在移动互联网时代,移动app能解决用户的很多生活琐事,比如 p导航:去任意陌生的地方 p周边:找餐馆.找酒店.找银行.找电影院 p n在上述应用中,都用到了地 ...

  6. 使用Boolean类型同步锁引起异常的分析

    原文地址 http://topic.csdn.net/u/20080710/19/f61cb4db-ddff-4457-a26a-4ea578b0cc6c.html?87447500 http://w ...

  7. svn服务配置

    1关闭所有svn服务 nie-xiao-bo-mac-pro:svnproject mac$ killall -9 svnserve 2.开启某文件路径svn服务 nie-xiao-bo-mac-pr ...

  8. Sqlplus的一般操作

    Sqlplus一些必要操作指令 1, 登陆sys 用户,需要加上 as sysdba Connect sys as sysdba; Input your password; Connected; 2, ...

  9. Java冒泡排序与二分法查找的代码随笔

    package javafirst; import java.util.Arrays; class MaoPao{ //升序排列 /** * @param arr 要排序的数组 * @return i ...

  10. 新一代Xamarin

    新一代Xamarin竟然可以将.NET代码原生编译成:Jar包供Java原生调用.swift类库.obj-c类库.C++类库 供目标平台传统代码直接调用 之前和很多朋友聊到Xamarin觉得确实不错, ...