比较来自世界各地的卖家的域名和 IT 服务价格

AngularJS 数据属性的绑定值

有谁知道如何将插值值绑定到数据属性 AngularJS?


<input data-custom-id="{{ record.id }}" type="text"/>


Angular, 似乎它不会插入此值,因为它与元素的结构分开。 有想法如何解决它?
已邀请:

三叔

赞同来自:

看起来没有问题仍然没有。 分析模板,以及我的控制器加载数据,但在分析模板时,还没有数据。 我需要数据的指令在那里,同时它只是收集空的macodas。

在团队的帮助下,我解决了这个问题 $watch:


$scope.$watch/'ready', function// {
if/$scope.ready == true/ {
//now the data-id attribute works
}
}/;


然后当控制器加载所有材料时 ajax, 你来弄吧:


$scope.ready = true;

郭文康

赞同来自:

在我看来,你真正需要什么, - 这是
http://docs.angularjs.org/api/ng.%24q
:


// for the purpose of this example let's assume that variables '$q' and 'scope' are
// available in the current lexical scope /they could have been injected or passed in/.

function asyncGreet/name/ {
var deferred = $q.defer//;

setTimeout/function// {
// since this fn executes async in a future turn of the event loop, we need to wrap
// our code into an $apply call so that the model changes are properly observed.
scope.$apply/function// {
if /okToGreet/name// {
deferred.resolve/'Hello, ' + name + '!'/;
} else {
deferred.reject/'Greeting ' + name + ' is not allowed.'/;
}
}/;
}, 1000/;

return deferred.promise;
}

var promise = asyncGreet/'Robin Hood'/;
promise.then/function/greeting/ {
alert/'Success: ' + greeting/;
}, function/reason/ {
alert/'Failed: ' + reason/;
/;


编辑:就是正确的,这里是使用控制器和绑定使用承诺的简单示例:


var app = angular.module/'myApp', []/;

app.controller/'MyCtrl', function/$scope, $q/ {
var deferredGreeting = $q.defer//;
$scope.greeting = deferredGreeting.promise;

/**
* immediately resolves the greeting promise
*/
$scope.greet = function// {
deferredGreeting.resolve/'Hello, welcome to the future!'/;
};

/**
* resolves the greeting promise with a new promise that will be fulfilled in 1 second
*/
$scope.greetInTheFuture = function// {
var d = $q.defer//;
deferredGreeting.resolve/d.promise/;

setTimeout/function// {
$scope.$apply/function// {
d.resolve/'Hi! /delayed/'/;
}/;
}, 1000/;
};
}/;​


在职的 JSFiddle:
http://jsfiddle.net/dain/QjnML/4/
/

基本上,这个想法是你可以关联承诺,它将一旦异步答案允许它就会才能执行。

要回复问题请先登录注册