Кажется, я неправильно понял, как работает функция $. Из следующего примера (plunker link).
HTML
<html ng-app="record">
<head>
<script data-require="[email protected]*" data-semver="1.2.0-rc2" src="http://code.angularjs.org/1.2.0-rc.2/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-controller="IndexController">
<input type="text" value="{{src}}"/>
<input type="text" value="{{RecordAddress}}"/>
<input type="text" value="{{FlashVars}}"/>
<input type="button" ng-click="handleClick()" value="click me"/>
<record src="{{src}}"></record>
</body>
</html>
JS
angular.module('record',[])
.controller("IndexController", function($scope)
{
console.log('controller called')
$scope.handleClick = function()
{
console.log('handleClick - called');
$scope.RecordAddress = 'rtmp://thisIsAnAddress';
$scope.FlashVars = 'userid=SomeId&filename=http://localhost/Content/ThisIsAnAddress/player.swf&mediaFormat=_video.mp4&mediaServerAddress=rtmp://ThisIsAnAddress&culture=en-GB'
$scope.src = $scope.RecordAddress+ '`' + $scope.FlashVars;
}
})
.directive('record', function ($location) {
return {
restrict: 'E',
scope: {
current: '=current'
},
link: function ($scope, element, attr) {
console.log('record directive - called');
console.log(attr);
attr.$observe('src', function(value)
{
console.log('record observe callback called!');
console.log('The value is: '+ value);
if(value && value !='recordValues')
{
var values = value.split('`');
console.log('video values:')
console.log(values);
element.html('<object position="relative" width="519px" height="520px" data="'+values[0]+'" type="application/x-shockwave-flash"><param name="FlashVars" value="'+values[1]+'" /><param name="AllowScriptAccess" value="always" /></object>');
}
else
{
element.html("<div>Please wait</div>")
}
}
);
}
}
});
Я бы ожидать, что "объект", чтобы быть оказаны при нажатии на кнопку в отличие от "Пожалуйста, подождите", что должно появляются, когда настройки не готовы. Однако он не вызывается, когда атрибут «src», по-видимому, обновляется. Может ли кто-нибудь объяснить мне, почему этот пример не работает?
Я думаю, вы должны смотреть на это тоже: http://docs.angularjs.org/api/ng.directive:ngSrc – unludo