NG-点击不火加时后负荷 [英] ng-click doesn't fire when added post load
问题描述
我试图做一个<一个href=\"http://pascal$p$pcht.github.io/angular-translate/docs/en/#/guide/06_variable-replacement\">variable更换同时,也使其具有可点击 ngClick 。
I'm trying to do a variable replacement while also making it clickable with ngClick.
我做了一个 plunker演示(单击该按钮并观察到输入框保持不变)
I made a plunker demo (click the button and observe that the input box stays unchanged)
标记:
<body ng-controller="Ctrl">
<input type="text" id="input" name="input" ng-model="myValue" test>
<p translate="VARIABLE_REPLACEMENT" translate-values="{{ 'translationData' }}"></p>
<p ng-bind-html="alink"></p>
</body>
角的东西:
var translations = {
VARIABLE_REPLACEMENT: 'Hi, {{name}}'
};
var app = angular.module('myApp', ['pascalprecht.translate', 'ngSanitize']);
app.config(['$translateProvider', function ($translateProvider) {
// add translation table
$translateProvider.translations(translations);
}]);
app.controller('Ctrl', ['$scope', '$sce', function ($scope, $sce) {
$scope.translationData = { name: 'foo'};
$scope.setValue = function(value) {
$scope.myValue = value;
};
}]);
app.directive('test', ['$translate', '$sce', function ($translate, $sce) {
return {
require: 'ngModel',
scope: false,
link: function (scope, element, attrs, ctrl) {
scope.$watch(attrs.ngModel, function (value) {
var a = $translate('VARIABLE_REPLACEMENT', {
name: '<button type="button" ng-click="setValue(\'foobar\')">click me</button>'
});
scope.alink = $sce.trustAsHtml(a);
});
}
};
}]);
现在的问题是:为什么没有单击该按钮时,NG-点击=的setValue('foobar的')
火灾。它应该设置在输入字段中的值'foobar的'。
The question is: Why doesn't ng-click="setValue('foobar')"
fire when the button is clicked. It's supposed to set the value 'foobar' in the input field.
推荐答案
在此期间有该问题的一个官方的解决方案:
In the meanwhile there is an official solution to that problem:
<p translate="varWithDirective" translate-compile></p>
会做编辑,而不需要编写自定义指令。
would do the compilation without the need of writing a custom directive.
有关详细信息:
https://github.com/angular-translate/angular-translate/issues/184
这篇关于NG-点击不火加时后负荷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!