Html AngularJS中是否有.data方法?

Html AngularJS中是否有.data方法?,html,angularjs,html5-data,Html,Angularjs,Html5 Data,假设我使用data属性在HTML中编写一个类似的测验: <p>The cow ran in front of the <input data-answer="car"></input>.</p> <p>Then the <input data-answer="man"></input> hit the breaks.</p> 奶牛跑在牛的前面 然后,球打到了破发处 如何访问AngularJS中的数

假设我使用data属性在HTML中编写一个类似的测验:

<p>The cow ran in front of the <input data-answer="car"></input>.</p>
<p>Then the <input data-answer="man"></input> hit the breaks.</p>
奶牛跑在牛的前面

然后,球打到了破发处


如何访问AngularJS中的数据应答属性?我知道如何在jQuery中使用.data方法实现这一点。AngularJS中是否有一个等价物?我做错了吗?我应该只使用jQuery吗?

使用一个指令,在该指令中,您将有一个
链接
函数:

link: function(scope, elem, attrs) {
    console.log(attrs.answer); //manipulate as you need
}

Angular还随jqLite提供,在实现整个jQ库之前,请确保检查该属性。

使用一个指令,在该指令中,您将有一个
链接
函数:

link: function(scope, elem, attrs) {
    console.log(attrs.answer); //manipulate as you need
}

Angular还随jqLite提供,在实现整个jQ库之前,请确保检查该属性。

使用一个指令,在该指令中,您将有一个
链接
函数:

link: function(scope, elem, attrs) {
    console.log(attrs.answer); //manipulate as you need
}

Angular还随jqLite提供,在实现整个jQ库之前,请确保检查该属性。

使用一个指令,在该指令中,您将有一个
链接
函数:

link: function(scope, elem, attrs) {
    console.log(attrs.answer); //manipulate as you need
}

AngularJS也随jqLite一起提供,在实现整个jQ库之前一定要检查一下。

是的,你做得完全不对:p.在AngularJS中,你很少需要直接操作DOM元素。通常您只操作数据

在这种情况下,您需要一个保存数据的控制器和HTML来显示数据。例如:

function AnswerController($scope){
    $scope.doSomething = function(){
        //do something with $scope.man and $scope.car
    }
}

<p>The cow ran in front of the <input ng-model="car" /><p>
<p>Then the <input ng-model="man" /> the breaks.</p>
功能应答控制器($scope){
$scope.doSomething=函数(){
//用$scope.man和$scope.car做点什么
}
}
母牛跑在狗的前面
然后,音乐响起

您还可以使用
获得一个包含所有答案的结果对象

请务必尝试熟悉角度的基本概念。最重要的规则(当您开始时,您确实必须向自己重复)是:几乎从不使用jQuery。如果您必须使用jQuery(您很少这样做),那么永远不要从控制器中使用它,而是始终从指令中使用它


上的“JavaScript项目”示例也非常有用。

是的,您做得完全错误:p.在AngularJS中,您很少需要直接操作DOM元素。通常您只操作数据

在这种情况下,您需要一个保存数据的控制器和HTML来显示数据。例如:

function AnswerController($scope){
    $scope.doSomething = function(){
        //do something with $scope.man and $scope.car
    }
}

<p>The cow ran in front of the <input ng-model="car" /><p>
<p>Then the <input ng-model="man" /> the breaks.</p>
功能应答控制器($scope){
$scope.doSomething=函数(){
//用$scope.man和$scope.car做点什么
}
}
母牛跑在狗的前面
然后,音乐响起

您还可以使用
获得一个包含所有答案的结果对象

请务必尝试熟悉角度的基本概念。最重要的规则(当您开始时,您确实必须向自己重复)是:几乎从不使用jQuery。如果您必须使用jQuery(您很少这样做),那么永远不要从控制器中使用它,而是始终从指令中使用它


上的“JavaScript项目”示例也非常有用。

是的,您做得完全错误:p.在AngularJS中,您很少需要直接操作DOM元素。通常您只操作数据

在这种情况下,您需要一个保存数据的控制器和HTML来显示数据。例如:

function AnswerController($scope){
    $scope.doSomething = function(){
        //do something with $scope.man and $scope.car
    }
}

<p>The cow ran in front of the <input ng-model="car" /><p>
<p>Then the <input ng-model="man" /> the breaks.</p>
功能应答控制器($scope){
$scope.doSomething=函数(){
//用$scope.man和$scope.car做点什么
}
}
母牛跑在狗的前面
然后,音乐响起

您还可以使用
获得一个包含所有答案的结果对象

请务必尝试熟悉角度的基本概念。最重要的规则(当您开始时,您确实必须向自己重复)是:几乎从不使用jQuery。如果您必须使用jQuery(您很少这样做),那么永远不要从控制器中使用它,而是始终从指令中使用它


上的“JavaScript项目”示例也非常有用。

是的,您做得完全错误:p.在AngularJS中,您很少需要直接操作DOM元素。通常您只操作数据

在这种情况下,您需要一个保存数据的控制器和HTML来显示数据。例如:

function AnswerController($scope){
    $scope.doSomething = function(){
        //do something with $scope.man and $scope.car
    }
}

<p>The cow ran in front of the <input ng-model="car" /><p>
<p>Then the <input ng-model="man" /> the breaks.</p>
功能应答控制器($scope){
$scope.doSomething=函数(){
//用$scope.man和$scope.car做点什么
}
}
母牛跑在狗的前面
然后,音乐响起

您还可以使用
获得一个包含所有答案的结果对象

请务必尝试熟悉角度的基本概念。最重要的规则(当您开始时,您确实必须向自己重复)是:几乎从不使用jQuery。如果您必须使用jQuery(您很少这样做),那么永远不要从控制器中使用它,而是始终从指令中使用它


上的“JavaScript项目”示例也非常有用。

attrs.answer
更好:
属性
已经规范化了DOM属性(请参见)Woops,确实如此!编辑!tymeJV,如果您原谅我的js noobness,那么我将如何访问输入字段的内容?我会使用ng模型吗?似乎如果我使用ng模型,那么我需要在每个测验问题的范围内有一个单独的变量-不好。是的,您将使用
ng模型
来访问值,可能类似于
ng模型='quick.question1'
,那么你就有了
$scope.quick
,它是所有问题的对象。
attrs.answer
更好:
属性
已经正常化了DOM属性(请参见)Woops,确实如此!编辑!tymeJV,如果您原谅我的js noobness,那么我将如何访问输入字段的内容?我会使用ng模型吗?似乎如果我使用ng模型,那么我需要在每个测验问题的范围内有一个单独的变量-不好。是的,您将使用
ng模型
来访问值,可能类似于
ng模型='quick.question1'
,因此您有
$