格式化双内标签文本的十进制数字(Formatting decimal digits for double inside label text)
我有这行代码:
label4.Text = "(" + x1 + ", 0), (" + x2 + ",0)";
x1和x2都是双精度值。 我无法用两位小数显示它们。 我知道我可以使用
{0:N2}
但我找不到正确的语法方式来使用它因为我想要显示的字符串中有两个值。 我应该如何编写它以使两个值( x1和x2 )显示在字符串中,只有2位十进制数字?I have this line of code:
label4.Text = "(" + x1 + ", 0), (" + x2 + ",0)";
Both x1 and x2 are double values. I cannot make them display with two decimal digits. I know that I can use
{0:N2}
but I cannot find right syntax way to use it because I have two values in string I want to display. How should I write it to make both values (x1 and x2) display in string with just 2 decimal digits?
原文:https://stackoverflow.com/questions/37435887
最满意答案
添加到您的范围:
scope { value: '=', controllerFunction: '=' }
在您的链接功能上,您可以致电:
scope.controllerFunction();
然后在HTML上,当你包含你的指令时,你需要将控制器函数作为属性传递:
<edit-in-place value="something" controller-function="testar">
Add to your scope:
scope { value: '=', controllerFunction: '=' }
And on your link function you call:
scope.controllerFunction();
And then on the HTML, when you include your directive, you need to pass the controller function as an attribute:
<edit-in-place value="something" controller-function="testar">
相关问答
更多-
我很幸运地回答了这个问题,但是为了完整起见,我发布了一个完整的答案,所以我们可以将这个问题标记为“已回答”。 这取决于你想通过共享一个控制器来完成什么; 您可以共享相同的控制器(尽管具有不同的实例),也可以共享相同的控制器实例。 共享控制器 通过将相同的方法传递给两个指令,两个指令可以使用相同的控制器,如下所示: app.controller( 'MyCtrl', function ( $scope ) { // do stuff... }); app.directive( 'directiveOne ...
-
无法从控制器中获取来自angularJs指令的trigg函数(Cant't get function in controller to trigg from angularJs directive)[2022-11-27]
添加到您的范围: scope { value: '=', controllerFunction: '=' } 在您的链接功能上,您可以致电: scope.controllerFunction(); 然后在HTML上,当你包含你的指令时,你需要将控制器函数作为属性传递:Add to your scope: scope { value: '=', contr ... -
var app = angular.module('exApp', []); app.controller("Ctrl", function ($scope) { $scope.test = function () { console.log("Hi you called ctrl function"); }; $scope.param = function(name){ console.log("My name is " + name); } $scope ...
-
你可以选择一些你想要的方式。 如果我是你,我会把你的AJAX调用转移到你的指令中以完全回避这个问题(甚至更好:将AJAX调用移到注入指令的服务中): angular.module('app').directive('directive', [ '$http', function($http) { return { link: link, scope: {} }; function link(sc ...
-
删除指令上的controller属性: .directive('myDirective', function() { return { scope: { output: '=', foo: '&', }, templateUrl: 'template.html', replace: true, // controller: 'myCtrl', }; }) 您将同一个控制器连接到指令作为父节点,它将覆盖您尝试通过隔离范围传递的所有属性。 ...
-
它不是在控制器之前调用链接函数,因为$scope.created.then()是异步的,在链接函数之后调用设置id的回调函数。 要修复它,您需要在链接函数中调用$scope.created.then() : link: function($scope, element, attrs) { $scope.created.then(function(createGal) { $scope.gallery.id = createGal.created_id; $(elem ...
-
我个人的偏好是使用一个事件。 使用手表 这个(我可以看到)唯一的缺点是它引入了一个小的性能问题,并且取决于代码基数,最终会有小事加起来。 使用控制对象 我认为这引入了指令和控制器之间的强耦合。 另外想象一下,项目的新开发人员进来看到this.controlObject.fn() ,他们就像...定义了哪里? 然后你开始搜索。 另外,如果你有一个不同的指令需要知道控制器的信息,会发生什么? 一个新的控制对象,一个新的函数定义..我不喜欢它。 使用事件 通过一个名为“component.x-updated”的通 ...
-
控制器范围可用于在声明控制器的DOM元素中显示为子节点的任何指令。 例如
-
AngularJS:从具有隔离范围的指令调用控制器函数(AngularJS : Call controller function from a directive with isolated scope)[2024-05-03]
您可以使用& like传递要调用的函数 var app = angular.module("app", []); app.controller("MainController", function($scope) { $scope.counter = 0; $scope.testFunction = function() { $scope.counter++; }; }); app.directive("test", function() { return { ... -
我是OP。 事实证明,使用$controllerProvider可以正常工作。 你必须传递一个构造函数; 不是一个实例。 beforeEach(module('app', function ($controllerProvider) { $controllerProvider.register('d1controller', function Mock(){ this.doStuff = function(){}; }); })); I'm the OP. It turns out tha ...