我在Angular Js中有一个警报功能,到目前为止只出现在屏幕上但您可以使用关闭功能关闭它。
到目前为止,这些参数在HTML标记中被调用,我想知道如何将样式应用于它们。例如。在警报主题和警报消息之间休息。
以下是代码:
索引
<alert
ng-show="showAlert"
topic="alertTopic"
description="alertMessage"
close="closeAlert()">
</alert>
指令:
parking.directive("alert", function () {
return {
restrict: 'E',
scope: {
topic: '=',
description: '=',
close: '&'
},
templateUrl: "alert.html",
replace: true
};
});
app:
var parking = angular.module("parking", []);
控制器:
parking.controller("parkingCtrl", function ($scope) {
$scope.appTitle = "[alert]";
$scope.alertTopic = "Something went wrong!";
$scope.alertMessage = "You must inform the plate and the color of the car!"
$scope.showAlert = true;
$scope.closeAlert = function () { $scope.showAlert = false; };
});
提醒
<div class="alert">
<span class="alert-topic">
<span ng-bind="topic"></span>
</span>
<span class="alert-description">
<span ng-bind="description"></span>
</span>
<a href="" ng-click="close()">Close</a>
</div>
答案 0 :(得分:4)
你去吧
int[] testArray = { 4, 3, -10, 4, 3, 0, -2, -5, 8 };
int result = testArray.OrderBy(Math.Abs).First(); //in this case 0 is closest to 0
答案 1 :(得分:4)
您正在寻找 ArgMin (参数 最小化某些功能)。 Linq 没有ArgMin
,但您可以在Aggregate
的帮助下实现它:
int result = testArray.Aggregate((a, s) => Math.Abs(a) < Math.Abs(s) ? a : s);