gpt4 book ai didi

javascript - 从作用域中获取 ng-init 值

转载 作者:行者123 更新时间:2023-11-30 16:35:50 27 4
gpt4 key购买 nike

我想从 Angular 范围获取 ng-init 值

Controller

$scope.data={}
$scope.initvalue="myvalue";

HTML

<input type="text" ng-model="data.value" ng-init="data.value= initvalue">

我想在输入框中设置 initvalue 并通过 ng-model 将它发送到 Controller (我想能够修改这个值所以我需要这样做)

最佳答案

这有意义吗?

http://jsfiddle.net/c7bsrenu/2/

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
$scope.data={}
$scope.initvalue="myvalue";
$scope.$watch('data.value', function(newVal, oldVal) {
console.log(newVal);
console.log(oldVal);
});
}

关于javascript - 从作用域中获取 ng-init 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32713297/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com