获得ng-model值onclick angulajs

时间:2016-11-06 08:57:30

标签: angularjs angularjs-ng-model

我想在角度函数中获得ng-model的值

<div id="script">
<div ng-repeat="selected in multiselectfields" id="generatedscript" ng-model="script">
"Insert into {{selected}} {{rules}}"
</div>
<input type="button" value="Generate PDF" ng-click="generatePDF();"/>
</div>

和角度函数是

$scope.generatePDF = function() {
 var MyDiv1 = document.getElementById('generatedscript').textContent;
console.log(document.getElementById('generatedscript').innerHTML);
};

它只显示动态创建的第一行 “插入idnumber 1”

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您不必使用document.getElementById,您可以直接打印ng-model scope 变量

$scope.generatePDF = function() {
console.log("Insert into " + $scope.selected);
};

答案 1 :(得分:0)

您可以将using System; using System.Collections.Generic; // for Dictionary using System.Linq; // for FirstOrDefault using System.Text.RegularExpressions; // for RegEx namespace ConsoleApplication { public class Program { public static void Main(string[] args) { Console.WriteLine("Hello World!"); var input = "What's the meaning of Stretch Hood"; var functions = new Dictionary<Regex, Action> { {new Regex("/^(What is|What's|Could you please tell me|Could you please give me) the meaning of (TF|FFS|SF|SHF|FF|Tube Film|Shrink Film|Stretch Hood|Stretch Hood Film|Flat Film)$/"), itemsIdentification}, {new Regex("/^(What is|What's|Could you please tell me|Could you please give me) the (stock|inventory) of ML$/"), mlSOH}, {new Regex("/^(What is|What's) (our|the) (stock|inventory|SoH) of (TF|FFS|SF|SHF|FF|Tube Film|Shrink Film|Stretch Hood|Stretch Hood Film|Flat Film)$/"), SoH}, {new Regex("/^(What is|What's|Calculate|How much is) ([\w.]+) (\+|and|plus|\-|less|minus|\*|\x|by|multiplied by|\/|over|divided by) ([\w.]+)$/"), math}, }; functions.FirstOrDefault(f => f.Key.IsMatch(input)).Value?.Invoke(); // This will execute the first Action found wherever the input matching the RegEx, the ?. means if not null ([Null-conditional Operators][1]) // or Action action; action = functions.FirstOrDefault(f => f.Key.IsMatch(input)).Value; if (action != null) { action.Invoke(); } else { // No function with that name } } public static void itemsIdentification() { Console.WriteLine("Fn 1"); } public static void mlSOH() { Console.WriteLine("Fn 2"); } public static void SoH() { } public static void math() { } } } 的值直接传递给您的函数: 在HTML中为ng-model

并在控制器中获取该值:

ng-click="generatePDF(script)"