小编Joh*_*tle的帖子

使用参数从指令调用控制器函数

如何使用某些参数从控制器调用函数?

我想将变量myVar赋给范围.$ apply(attrs.whattodo);

HTML:

<div ng-app="component">
  <div ng-controller="ctrl">
    <span ng-repeat="i in myarray">
     <span  customattr  whattodo="addVal">{{i}}</span>
    </span>
  </div>
Run Code Online (Sandbox Code Playgroud)

控制器JS:

   function ctrl($scope) {
      $scope.myarray = [1];
      $scope.addVal = function (value) {
          $scope.myarray.push(value);
      }
   }
Run Code Online (Sandbox Code Playgroud)

指令JS:

angular.module('component', []).directive('customattr', function () {
  return {
      restrict: 'A',
      link: function (scope, element, attrs) {
          var myVar = 5;
          scope.$apply(attrs.whattodo);
      } 
  }; 
}); 
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-directive

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

在matlab中着色矩阵

可能重复:
如何使用显示的颜色和值显示矩阵?

NxN在MATLAB中基本上有一个(编辑:N可以达到80)矩阵的双重和我将它绘制为一个数组(我想看到数字)和一些单元格应该是彩色的(决定如何我为我的数字着色与数字无关).

我想到了不同的方法:

  • 创建一个网格作为一个图像并用文本覆盖它,但MATLAB的图将是可怕的,因为它将删除一些像素来调整图像的大小(我的矩阵可以在周围80x80).

  • 出口到excel?我不知道如何为细胞着色.

有帮助吗?

因为图像有时更有帮助:

在此输入图像描述

matlab plot image colors matrix

6
推荐指数
1
解决办法
4541
查看次数

范围破坏输入的ngmodel的指令

我应该给我的指令赋予什么范围,以便输入显示初始值"Toto"?我不想占用范围:是的

HTML代码:

<!doctype html>
<html ng-app="plunker" >
<head>
  <meta charset="utf-8">
  <title>AngularJS Plunker</title>
  <script>document.write('<base href="' + document.location + '" />');</script>
  <link rel="stylesheet" href="style.css">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.js"></script>
  <script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
   <input customattr type = "text" ng-model="value.name" />   
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

JS代码:

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.value = {"name":"Toto", "id":1};

});

    app.directive('customattr', function () {
      return {
          restrict: 'A',
          scope: {
          },
          link: function (scope, element, attrs) {

          } 
      }; 
    });
Run Code Online (Sandbox Code Playgroud)

Plunker:http://plnkr.co/edit/JxWElWhTeBbNpFHS0wYT

angularjs angularjs-directive

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