我是Angular.js的初学者,我有两个问题。
首先,我创建了一个名为nwCard的指令。在链接功能上,我试图显示元素P.但是变量元素未定义。
其次,在控制器InvoicesCtrl上我有一个addShow函数,可以从表单中保存新记录。它运行良好,但只有在重新加载页面时才会更新指令nwCard。我可以在InvoiceCtrl保存记录后更新nwCard吗?
谢谢你们。
angular.module('playgroundApp')
.directive('nwCard', function() {
var num = 1;
return {
restrict: 'E',
templateUrl: 'views/invoices/directives/nw-card.html',
scope: {
header: '=',
description: '=',
},
link: function(scope, element, attrs) {
element.on("click", function() {
element(".card p").show(); //Investigate: do not work
});
},
controller: function($scope, Note) {
$scope.movies = Note.query();
}
};
})
.controller('InvoicesCtrl', function ($scope, Note) {
$scope.addShow = function() {
Note.save($scope.invoice).$promise
.then(function(data) {
$scope.invoice = '';
$scope.addForm.$setPristine();
console.log($scope.movies)
})
.catch(function(response) {
alert(response)
})
}
})
angular.module('playgroundApp')
.directive('nwCard', function() {
var num = 1;
return {
restrict: 'E',
templateUrl: 'views/invoices/directives/nw-card.html',
scope: {
header: '=',
description: '=',
},
link: function(scope, element, attrs) {
element.on("click", function() {
element(".card p").show(); //Investigate: do not work
});
},
controller: function($scope, Note) {
$scope.movies = Note.query();
}
};
})
.controller('InvoicesCtrl', function ($scope, Note) {
$scope.addShow = function() {
Note.save($scope.invoice).$promise
.then(function(data) {
$scope.invoice = '';
$scope.addForm.$setPristine();
console.log($scope.movies)
})
.catch(function(response) {
alert(response)
})
}
})