我是使用 angularjs 的新手,我正在尝试创建指令。我的查询是,如何$http.get
从 html 更改 URL。这是我的代码:
HTML指令:
<form-directive text="Formulario con Directiva" nameinput="true"
namelabel="Nombre:" emailinput="true"
emaillabel="Email:" subjetinput="true" subjetlabel="Asunto:"
message="true" messagelabel="Mensaje:"
dataurl="URL to change">
</form-directive>
JS:
<script>
angular.module('testDirective', [])
.controller('testDir', function ($scope, $http) {
$scope.textoFalopa = "Hola, es una prueba";
})
.directive('formDirective', function () {
return {
restrict: "EA",
templateUrl: './template.html',
scope: {
text: '@',
nameinput: '=nameinput',
namelabel: '@',
emailinput: '=emailinput',
emaillabel: '@',
subjetinput: '=subjetinput',
subjetlabel: '@',
message: '=message',
messagelabel: '@',
dataurl:'='
},
controller: ['$scope', '$http', function ($scope, $http) {
$http.get('https://jsonplaceholder.typicode.com/users').then(function (remotedata) {
console.log(remotedata.data);
$scope.data = remotedata.data;
});
}],
link: function (scope) {
console.log(scope);
}
};
});
</script>
谢谢!