Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
179
rated 0 times [  180] [ 1]  / answers: 1 / hits: 18486  / 11 Years ago, fri, august 9, 2013, 12:00:00

I'm learning Angular.js and I set <title>{{title}}</title> and I try to change that using select element



<select ng-model=user.title>
<option value=Lorem>Lorem</option>
<option value=Ipsum>Ipsum</option>
<option value=Dolor>Dolor</option>
</select>


I try ng-change and ng-select with set()



function ctrl($scope) {
$scope.title = 'hello'; // this set the title
$scope.set = function() {
$scope.title = $scope.user.title; // this not
};
}


THe function don't work, but it work when I just set it without a function.



I also try to create change directive:



app.directive('change', function() {
console.log('change');
return {
link: function(scope, element, attrs) {
console.log(arguments);
element[0].onChange = function() {
scope[attrs[0]]();
};
}
};
});


but this too don't work. Console.log don't execute at all.


More From » angularjs

 Answers
0

Everything should work fine without extra code:



<html data-ng-app=app>
<head>
<title>{{title}}</title>
</head>
<body>
{{title}}
<select ng-model=title>
<option value=Lorem>Lorem</option>
<option value=Ipsum>Ipsum</option>
<option value=Dolor>Dolor</option>
</select>
</body>
</html>


And that's all. Here is a pen.


[#76423] Thursday, August 8, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tobyl

Total Points: 598
Total Questions: 110
Total Answers: 114

Location: Vietnam
Member since Sat, Feb 12, 2022
2 Years ago
tobyl questions
Tue, Aug 10, 21, 00:00, 3 Years ago
Wed, Jan 13, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
;