Javascript 未调用angularjs模板ng更改

Javascript 未调用angularjs模板ng更改,javascript,angularjs,javascript-events,Javascript,Angularjs,Javascript Events,我有一个指令,它根据指令值呈现适当的模板。它呈现一个由多个部分组成的表单。我想收集它们,并在任何更改时进行评估 如果我使用ng change w/o指令,一切似乎都正常工作,但当调用模板且ng change位于模板内部时,情况并非如此 指令看起来不像这样: myApp.directive('render', function () { return function (scope, element, attrs) { return attrs.$observe('para

我有一个指令,它根据指令值呈现适当的模板。它呈现一个由多个部分组成的表单。我想收集它们,并在任何更改时进行评估

如果我使用ng change w/o指令,一切似乎都正常工作,但当调用模板且ng change位于模板内部时,情况并非如此

指令看起来不像这样:

myApp.directive('render', function () {
    return function (scope, element, attrs) {
        return attrs.$observe('parameters', function (value) {
            var attributes, options, renderValue;
            attributes = scope.$eval("{" + attrs.parameters + "}");
            renderValue = attrs.render;
            if (renderValue === "input") {
                return {
                    restrict: 'E',
                    replace: true,
                    template: element.html('<label for="' + element.text() + '">' + element.text() + ' </label><input name="' + element.text() + '" type=' + attributes.type + ' class="large-12 columns" ng-model="' + element.text() + '" ng-change="change()">')
                };
            }
        })
    }

});
myApp.directive('render',function(){
返回函数(范围、元素、属性){
返回属性$observe('parameters',函数(值){
var属性、选项、renderValue;
attributes=scope.$eval(“{”+attrs.parameters+“}”);
renderValue=attrs.render;
如果(renderValue==“输入”){
返回{
限制:'E',
替换:正确,
模板:element.html(“”+element.text()+“”)
};
}
})
}
});
如果要渲染select、radio等,它还有一些其他功能。但想法是一样的

如果你能帮我,我将不胜感激

编辑


在JSFIDLE上粘贴错误,现已更正

Hmm您认为一个通用的实现也可以与ngRepeat一起重用吗

var-app=angular.module(“app”,[]);
应用指令(“金额”,函数($compile){
返回{
限制:“E”,
模板:“”,
替换:正确,
编译:函数编译(tElement、tAttrs){
返回功能(范围、IELENT、iAttrs){
变量属性=$(iElement).prop(“属性”);
var$input=$(iElement).find(“input”);
$.each(attributes,function(){//循环所有属性并将它们复制到
如果(this.name!=“class”){
$input.attr(this.name,this.value);
}
});
$compile($input)(范围);//编译输入
};
}
};
});
学分:


希望能有帮助

不知道你在问什么。显然,你贴的小提琴与问题不符。
var app = angular.module("app", []);
app.directive("amount", function ($compile) {
    return {
        restrict: "E",
        template: "<div class='amount'><input type='text' /></div>",
        replace: true,
        compile: function compile(tElement, tAttrs) {
            return function (scope, iElement, iAttrs) {
                var attributes = $(iElement).prop("attributes");
                var $input = $(iElement).find("input");
                $.each(attributes, function () { //loop over all attributes and copy them to the <input/>
                    if (this.name !== "class") {
                        $input.attr(this.name, this.value);
                    }
                });
                $compile($input)(scope); //compile the input
            };
        }
    };
});