Javascript 如何将样式应用于";“警惕”;AngularJs中的函数

Javascript 如何将样式应用于";“警惕”;AngularJs中的函数,javascript,css,angularjs,Javascript,Css,Angularjs,我在Angular Js中有一个警报功能,到目前为止,它只是出现在屏幕上,但您可以使用close功能将其关闭。 到目前为止,这些参数是在HTML标记中调用的,我想知道如何将样式应用于它们。在警报主题和警报消息之间切换 代码如下: 索引 应用程序: var parking = angular.module("parking", []); 控制器: parking.controller("parkingCtrl", function ($scope) { $scope.appTit


我在Angular Js中有一个警报功能,到目前为止,它只是出现在屏幕上,但您可以使用close功能将其关闭。
到目前为止,这些参数是在HTML标记中调用的,我想知道如何将样式应用于它们。在警报主题和警报消息之间切换

代码如下:
索引

应用程序:

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>

给你

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

您正在寻找ArgMin(一个最小化某些函数的参数)。Linq没有
ArgMin
,但是您可以在
Aggregate
的帮助下实现它:

int result = testArray.Aggregate((a, s) => Math.Abs(a) < Math.Abs(s) ? a : s);
int result=testArray.Aggregate((a,s)=>Math.Abs(a)
你的代码让它看起来好像你什么都没试过,什么都没试过…(数组看起来像{0,-2,3,3,4,4,-5,8,-10})@DanielFrühauf这是正确的这是一个O(N.Log(N))问题的O(N)解决方案…认真地说,由于运行时间的原因,与另一个答案相比,你的答案是正确的吗?对于一个包含10个项目的数组,我更关心易于理解的代码read@fubo我没有投反对票。然而,值得指出的是运行时的问题——不要仅仅因为示例数据只包含10个项目就假设它只会用于这些项目!但是我同意,对于预期用途来说,它可能是完全可以接受的。这是一个更好的选择,因为它是一个O(N)解决方案。为什么不只是
testArray.Min()
,并适当地检查数组是否为空?@john:我的目标是展示如何在一般情况下计算
ArgMin
(查找该项时应……)
testArray.Min(item=>Math.Abs(item))
在一般情况下不起作用:
[-1,2,3]
应该返回
-1
,而不是
1
@john,但我们正在寻找最接近零的值,而不是最小值。只想指出,如果您碰巧使用了(相当常见的),答案变成简单的
result=testArray.MinBy(Math.Abs)
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
int result = testArray.Aggregate((a, s) => Math.Abs(a) < Math.Abs(s) ? a : s);